//加载数据库驱动程序
new com.mysql.jdbc.Driver();
//连接数据库
conn = DriverManager.getConnection("jdbc:mysql://localhost/user? user='root'&password=''","root","");
//创建一个 Statement 对象来将 SQL 语句发送到数据库
stmt = conn.createStatement();
//给定的 SQL 语句
rs = stmt.executeQuery("select * from info");
executeQuery()和executeUpdate()的区别
executeQuery:执行给定的 SQL 语句,该语句返回单个 ResultSet
对象。
executeUpdate:执行给定 SQL 语句,该语句可能为 INSERT
、UPDATE
或 DELETE
语句,或者不返回任何内容的 SQL 语句(如 SQL DDL 语句)。