executeQuery对应查询、executeUpdate对应改动、execute对应建表
设已经创建一个hero表 有id,name,money 三个字段
//DBUtils链接数据库
try (Connection conn = DBUtils.getConn()){
//创建执行SQL语句的对象
Statement s = conn.createStatement();
//执行创建表的SQL语句
s.execute("create table hero(id int primary key auto_increment," +"name varchar(20),money double(10,2))");
s.executeUpdate("insert into hero values(null,'"+name+"',"+money+")";
//在里面查询出英雄表的所有信息并在控制台输出
ResultSet rs = s.executeQuery("select * from hero");
while (rs.next()){
int id = rs.getInt(1);
String name = rs.getString(2);
double money = rs.getDouble(3);
System.out.println(id+":"+name+":"+money);
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}