java程序操作MySQL数据库
2012-12-08 15:43:06 来源:WEB开发网核心提示: } public people query_people(String uid) {database_manage db_obj = new database_manage();// String adminid=null;String uid_new, name, banji;uid_new = null;name
}
public people query_people(String uid) {
database_manage db_obj = new database_manage();
// String adminid=null;
String uid_new, name, banji;
uid_new = null;
name = null;
banji = null;
String sql_query = "select * from people where uid='" + uid + "'";
database_manage db_obj = new database_manage();
// String adminid=null;
String uid_new, name, banji;
uid_new = null;
name = null;
banji = null;
String sql_query = "select * from people where uid='" + uid + "'";
try {
ResultSet rs = db_obj.query(sql_query);
if (rs.next()) {
uid_new = rs.getString("uid");
name = rs.getString("name");
banji = rs.getString("banji");
}
} catch (Exception e) {
e.getMessage();
}
people new_people = new people(uid_new, name, banji);
return new_people;
}
ResultSet rs = db_obj.query(sql_query);
if (rs.next()) {
uid_new = rs.getString("uid");
name = rs.getString("name");
banji = rs.getString("banji");
}
} catch (Exception e) {
e.getMessage();
}
people new_people = new people(uid_new, name, banji);
return new_people;
}
public people[] query_people_byscore(int score) {
database_manage db_obj = new database_manage();
String uid_new, name, banji;
uid_new = null;
name = null;
banji = null;
int score_new = 0;
database_manage db_obj = new database_manage();
String uid_new, name, banji;
uid_new = null;
name = null;
banji = null;
int score_new = 0;
String sql_query = "select * from people where score=" + score;// sql查询语句
try {
ResultSet rs = db_obj.query(sql_query);// 查询后,返回结果集
int num = 0;
ResultSet rs_new = rs;
while (rs_new.next()) {// 统计结果集中学生个数
num++;
}
// System.out.println(num);
ResultSet rs = db_obj.query(sql_query);// 查询后,返回结果集
int num = 0;
ResultSet rs_new = rs;
while (rs_new.next()) {// 统计结果集中学生个数
num++;
}
// System.out.println(num);
people_array1 = new people[num];
int i = 0;
rs.beforeFirst();// 返回结果集的开始
while (rs.next()) {
int i = 0;
rs.beforeFirst();// 返回结果集的开始
while (rs.next()) {
uid_new = rs.getString("uid");
name = rs.getString("name");
banji = rs.getString("banji");
score_new = rs.getInt("score");
name = rs.getString("name");
banji = rs.getString("banji");
score_new = rs.getInt("score");
people_array1[i] = new people(uid_new, name, banji, score_new);
i++;
}
} catch (Exception e) {
e.getMessage();
}
return people_array1;
}
i++;
}
} catch (Exception e) {
e.getMessage();
}
return people_array1;
}
public static void main(String args[]) {
/*
* people new_people=new people();
*
* manage mr=new manage(); //mr.add_people("000","小明");插入一个学生的信息
*
* new_people=mr.query_people("001");//查询uid=001的学生信息,返回对象 System.out.
* println(""+new_people.getName()+" "+new_people.getBanji());
* mr.update_people("004", "小王");更新一个学生的信息
*
* new_people=mr.query_people("004");//更新后查询
*
* System.out.println(""+new_people.getName()+" "+new_people.getBanji(
* ));
*/
* people new_people=new people();
*
* manage mr=new manage(); //mr.add_people("000","小明");插入一个学生的信息
*
* new_people=mr.query_people("001");//查询uid=001的学生信息,返回对象 System.out.
* println(""+new_people.getName()+" "+new_people.getBanji());
* mr.update_people("004", "小王");更新一个学生的信息
*
* new_people=mr.query_people("004");//更新后查询
*
* System.out.println(""+new_people.getName()+" "+new_people.getBanji(
* ));
*/
更多精彩
赞助商链接