WEB开发网
开发学院软件开发Java java程序操作MySQL数据库 阅读

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 + "'";
 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;
 }
 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;
 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);
  people_array1 = new people[num];
  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");
  people_array1[i] = new people(uid_new, name, banji, score_new);
  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(
  * ));
  */

上一页  1 2 3 4  下一页

Tags:java 程序 操作

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接