final String url = "jdbc:mysql://localhost:3306/filedb";
final String username = "root";
final String password = "123456";
Connection conn;
Statement stmt;
ResultSet res;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement();
stmt.execute("update user set pwd = /"123456/" where username = /"ttt/"");
stmt.execute("insert into user(username) value(/"tigerting/")");
res = stmt.executeQuery("select * from user where username = /"ttt/"");
while (res.next()) {
final String name = res.getString("username");
final String pwd = res.getString("pwd");
System.out.println("name is :" + name);
System.out.println("password is :" + pwd);
}
res.close();
conn.close();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
java MySql
最新推荐文章于 2025-05-18 12:20:23 发布