@ -29,7 +29,7 @@ public class UserService {
}
public int login ( String username , String password ) {
conn = db . getConnection ( ) ;
conn = DatabaseHelper . getConnection ( ) ;
Statement sttmt ;
try {
sttmt = conn . createStatement ( ) ;
@ -57,7 +57,7 @@ public class UserService {
}
public boolean register ( User user ) {
conn = db . getConnection ( ) ; //将用户的信息上传到数据库, 上传成功返回true, 失败false
conn = DatabaseHelper . getConnection ( ) ; //将用户的信息上传到数据库, 上传成功返回true, 失败false
try {
String sql = "insert into user_info(username,password,role,phone) values('" + user . getUsername ( ) + "','" + user . getPassword ( ) + "','" + user . getRole ( ) + "','" + user . getPhone ( ) + "')" ;
Statement sttmt = conn . createStatement ( ) ;
@ -71,7 +71,7 @@ public class UserService {
}
public boolean donate ( long stu_id , long user_id , float money ) {
conn = db . getConnection ( ) ; //将用户捐款信息上传到数据库, 成功返回true, 失败返回false
conn = DatabaseHelper . getConnection ( ) ; //将用户捐款信息上传到数据库, 成功返回true, 失败返回false
try {
String time = getNetTime ( ) ;
// Date date = new Date();sdf.format(date)
@ -101,13 +101,17 @@ public class UserService {
String format = formatter . format ( calendar . getTime ( ) ) ;
return format ;
}
public boolean longterm ( String name , String phone , String descri , Long ID ) {
conn = db . getConnection ( ) ; //将长期资助信息上传到数据库, 成功返回true, 失败返回false
public boolean longterm ( String name , Long stu_id , Long user_id ) {
conn = DatabaseHelper . getConnection ( ) ; //将长期资助信息上传到数据库, 成功返回true, 失败返回false
try {
String sql = "insert into usr_help_req(name,phone,descri,ID) values('" + name + "','" + phone + "','" + descri + "','" + ID + "')" ;
//name,phone,descri,ID
String sql = "insert into usr_long_help(stu_id,user_id,flags) values('" + stu_id + "','" + user_id + "','" + 0 + "')" ;
// where null=(select name from user_info where user_id='"+user_id+"')
String sql1 = "update user_info set name='" + name + "' where (select name from (select name from user_info where user_id='" + user_id + "') t1 ) is not null" ;
//update user_info set name="你的好爸爸" where (select name from (select name from user_info where user_id=1) t1 ) is null
//stuid,useerid,flags
Statement sttmt = conn . createStatement ( ) ;
sttmt . executeUpdate ( sql ) ;
sttmt . executeUpdate ( sql1 ) ;
sttmt . close ( ) ;
return true ;
}
@ -120,7 +124,7 @@ public class UserService {
//SQLiteDatabase sdb=dbHelper.getReadableDatabase();
String sql = "select * from user_info where username = '" + username + "'and password = '" + password + "'" ;
User user = new User ( ) ;
conn = db . getConnection ( ) ;
conn = DatabaseHelper . getConnection ( ) ;
try {
Statement sttmt = conn . createStatement ( ) ;
ResultSet rs = sttmt . executeQuery ( sql ) ;
@ -141,7 +145,7 @@ public class UserService {
public boolean UploadInfo ( News news ) { //用户上传信息到数据库,服务器
String sql = "insert into stu_info(name,descri) values('" + news . getName ( ) + "','" + news . getDescri ( ) + "')" ;
conn = db . getConnection ( ) ;
conn = DatabaseHelper . getConnection ( ) ;
try {
Statement sttmt = conn . createStatement ( ) ;
sttmt . executeUpdate ( sql ) ;
@ -156,7 +160,7 @@ public class UserService {
public void getAllNews ( Context context , ArrayList < News > list ) {
//ArrayList<News> mlist = list;
String sql = "select * from stu_info where flags = 1" ;
conn = db . getConnection ( ) ;
conn = DatabaseHelper . getConnection ( ) ;
try {
Statement sttmt = conn . createStatement ( ) ;
ResultSet rs = sttmt . executeQuery ( sql ) ;
@ -178,7 +182,7 @@ public class UserService {
public void getDonateRecords ( ArrayList < Record > recordlist , long user_id ) {
String sql = "select * from record,stu_info where record.stu_id = stu_info.stu_id and record.user_id='" + user_id + "'" ;
conn = db . getConnection ( ) ;
conn = DatabaseHelper . getConnection ( ) ;
try {
Statement sttmt = conn . createStatement ( ) ;
ResultSet rs = sttmt . executeQuery ( sql ) ;
@ -199,7 +203,7 @@ public class UserService {
public void getDonatedRecords ( ArrayList < Record > recordlist , long id ) {
String sql = "select * from record,user_info where record.user_id = user_info.user_id and record.stu_id = '" + id + "'" ;
conn = db . getConnection ( ) ;
conn = DatabaseHelper . getConnection ( ) ;
try {
Statement sttmt = conn . createStatement ( ) ;
ResultSet rs = sttmt . executeQuery ( sql ) ;