sql 删除表格里面的用户和修改密码的问题
package com.demo.jdbc;import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.mysql.jdbc.PreparedStatement;
public class JdbcConnectMain {
public static void main(String[] args) throws Exception, IllegalAccessException, ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = java.sql.DriverManager
.getConnection(
"jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=GBK",
"root", "123456");
readDataFromDB(con);
insertInto(con);
// delete,update
// badqiu的密码改成为123456;用到数据库的UPDATE功能
// 把用户名jz删除
}
private static void insertInto(Connection con) throws SQLException {
java.sql.PreparedStatement ps = con.prepareStatement("insert into user(username,pwd) values (?,?)");
ps.setString(1, System.currentTimeMillis()+"");
ps.setString(2, "pwd_123456");
ps.execute();
}
private static void readDataFromDB(Connection con) throws SQLException {
Statement stmt = null;
ResultSet rst = null;
try {
stmt = con.createStatement();
rst = stmt.executeQuery("select * from user");
while(rst.next()) {
System.out.println("username:"+rst.getString(1)+" pwd:"+rst.getString("pwd"));
}
}finally {
stmt.close();
rst.close();
}
}
}