「java更改mysql」java更改jdk版本

博主:adminadmin 2023-01-02 13:24:09 409

今天给各位分享java更改mysql的知识,其中也会对java更改jdk版本进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java修改MySQL表中的数据问题:如代码

你的代码写的很乱。

首先if (jpf3.equals(jpf2)) {

if (jpf1.equals(mima)) {

String str="update 人员信息表 set 密码 = '001' where 人员编号 = '001'; ";

//(如果这句换成: String str="update 人员信息表 set 密码 = 'jpf3' where 人员编号 = 'jtf1'; ";就不会修改成功。 为什么啊? 求高人啊!正确格式是什么呢?

Statement statement =con.createStatement();

int s=statement.executeUpdate(str);

JOptionPane.showMessageDialog(null, "修改成功");

这一部分是要写在try{}里面的,finally{}里面要对PreparedStatement进行判断,要关闭。

你的sql语句里面使用的是变量

如果变量是String类型的: String str="update 人员信息表 set 密码 = '"+jpf3+"' where 人员编号 = '"+jtf1+"';

如果是int,long,double之类的:String str="update 人员信息表 set 密码 = "+jpf3+" where 人员编号 = "+jtf1+";

如何在java中修改MySQL表中的数据,下面代码不对。求帮忙

update user set name=?,sex=?,birthday=? where id=? 中有四个问号( 也就是占位符),但是prept只绑定了三次值。第四个占位符没绑定

java程序操作MySQL数据库

数据库内容

  java源代码 (代码实现的是查询成绩为 的人员信息 至于其他功能的 代码中有注释) 注意 在eclipse里运行程序的时候 要工程里插入jar包 否则运行异常! import java sql *; import java io *; class database_manage {  public Connection conn = null;  public ResultSet rs = null;  private String DatabaseDriver = " mysql jdbc Driver";  // DataSource 数据源名称DSN  private String DatabaseConnStr = "jdbc:mysql://localhost: /people_manage?useUnicode=truecharacterEncoding=utf "  + " root root";  public void setDatabaseDriver(String Driver) { this DatabaseDriver = Driver;  }  public String getDatabaseDriver() { return (this DatabaseDriver);  }  public void setDatabaseConnStr(String ConnStr) { this DatabaseConnStr = ConnStr;  }  public String getDatabaseConnStr() { return (this DatabaseConnStr);  }  public database_manage() {// 构造函数连接数据库 try {  Class forName(DatabaseDriver); } catch (java lang ClassNotFoundException e) {  System err println("加载驱动器有错误:" + e getMessage());  System out print("执行插入有错误:" + e getMessage());// 输出到客户端 }  }  public ResultSet query(String sql) {// 查询数据库 rs = null; try {  conn = DriverManager   getConnection(  "jdbc:mysql://localhost: /people_manage?useUnicode=truecharacterEncoding=utf "  "root" "root");  Statement stmt = conn createStatement();  rs = stmt executeQuery(sql); } catch (SQLException ex) {  System err println("执行查询有错误:" + ex getMessage());  System out print("执行查询有错误:" + ex getMessage()); // 输出到客户端 }

return rs;

 }  public int update_database(String sql) {// 更新或插入数据库 int num = ; try {  conn = DriverManager   getConnection(  "jdbc:mysql://localhost: /people_manage?useUnicode=truecharacterEncoding=utf "  "root" "root");  Statement stmt = conn createStatement();  num = stmt executeUpdate(sql); } catch (SQLException ex) {  System err println("执行插入有错误:" + ex getMessage());  System out print("执行插入有错误:" + ex getMessage());// 输出到客户端 }  CloseDataBase(); return num;  }  public void CloseDataBase() {// 关闭数据库 try {  conn close(); } catch (Exception end) {  System err println("执行关闭Connection对象有错误 " + end getMessage());  System out print("执行执行关闭Connection对象有错误 有错误:" + end getMessage()); // 输出到客户端 }  } } class people {  private String uid;  private String name;  private String banji;  private int score;  public people() {  }  public people(String uid String name String banji) { this uid = uid; this name = name; this banji = banji;  }  public people(String uid String name String banji int score) { this uid = uid; this name = name; this banji = banji; this score = score;  }  public String getUid() { return uid;  }  public void setUid(String uid) { this uid = uid;  }  public String getName() { return name;  }  public void setName(String name) { this name = name;  }  public String getBanji() { return banji;  }  public void setBanji(String banji) { this banji = banji;  }  public int getScore() { return score;  }  public void setScore(int score) { this score = score;  } } public class manage {  private people[] people_array ;// 对象数组  public void add_people(String uid String name) {  String sql = "insert people (uid name) values ( " + uid + " " + name + " )";// sql插入语句 // String sql = "insert people (uid name) values ( uid tom )";  database_manage db_obj = new database_manage(); db_obj update_database(sql);  }  public void update_people(String uid String name) {  String sql = "update people set name= " + name + " where uid= " + uid + " "; database_manage db_obj = new database_manage(); db_obj update_database(sql);  }  public void delete_people(String uid) {  String sql = "delete from people  where uid= " + uid + " ";  database_manage db_obj = new database_manage();  db_obj update_database(sql);  }  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 = ;

String sql_query = "select * from people where score=" + score;// sql查询语句

try {

ResultSet rs = db_obj query(sql_query);// 查询后 返回结果集

int num = ;

ResultSet rs_new = rs;

while (rs_new next()) {// 统计结果集中学生个数

num++;

}

// System out println(num);

people_array = new people[num];

int i = ;

rs beforeFirst();// 返回结果集的开始

while (rs next()) {

uid_new = rs getString("uid");

name = rs getString("name");

banji = rs getString("banji");

score_new = rs getInt("score");

people_array [i] = new people(uid_new name banji score_new);

i++;

}

} catch (Exception e) {

e getMessage();

}

return people_array ;

}

public static void main(String args[]) {

/*

* people new_people=new people();

*

* manage mr=new manage(); //mr add_people(" " "小明");插入一个学生的信息

*

* new_people=mr query_people(" ");//查询uid= 的学生信息 返回对象 System out

* println(""+new_people getName()+"  "+new_people getBanji());

* mr update_people(" " "小王");更新一个学生的信息

*

* new_people=mr query_people(" ");//更新后查询

*

* System out println(""+new_people getName()+"  "+new_people getBanji(

* ));

*/

manage mr = new manage();

// mr delete_people(" ");删除uid= 的学生信息

people[] people_array;// 声明对象数组

people_array = mr query_people_byscore( );// 返回成绩为一百的学生类数组 后输出

int num = ;

num = people_array length;

for (int i = ; i num; i++) {

System out println(people_array[i] getUid() + " "

+ people_array[i] getName() + "  "

+ people_array[i] getBanji() + "  "

+ people_array[i] getScore());

}

}

}

lishixinzhi/Article/program/Java/JSP/201311/20030

如何用java实现对mysql进行增删改查

jdbc。。首先你的下载mysql然后下载jdbc驱动,然后在你的代码里与数据库连接,连接成功后就可以在代码里用sql语句对mysql实现增删改查了

java更改mysql的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java更改jdk版本、java更改mysql的信息别忘了在本站进行查找喔。