51,412
社区成员
发帖
与我相关
我的任务
分享public class DbTools {
Connection connection;
public Connection getConn() {
try{
//load the driver
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String userName = "system";
String password = "123";
//get the connection object
connection = DriverManager.getConnection(url, userName, password);
}catch (ClassNotFoundException e){
e.printStackTrace();
}catch (SQLException e){
e.printStackTrace();
}
return connection;
}
} public static void searchJDBC(String name){
String sql = String.format("select * from useinfo where username='%s'", name);
DbTools dbTools = new DbTools();
Connection connection = dbTools.getConn();
try{
//create the statement object
Statement statement=connection.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
while(resultSet.next()) {
System.out.println(resultSet.getString("username")+ " "+ resultSet.getString("password"));
}
}catch (SQLException e){
e.printStackTrace();
}
}数据库里面是没有这条记录的,但是用Java查询还是存在。我后来再数据库里面添加一条新的纪录,发现用Java查询不到,应该是数据库的数据没有实时更新到Java,Java一直是读的之前的数据 数据库里删除数据之后执行select * from useinfo where username='%s'",查询一下有没有删除成功
数据库里删除数据之后执行select * from useinfo where username='%s'",查询一下有没有删除成功