一:以往项目所用mysql语句
二:完整的Mysql语句
1.建立数据库: Create Database 库名;
2.建立数据表: Create Table 表名 (字段名,字段名);
3.删除数据库:Drop Table 表名;
4.将表中记录清空: Delete from 表名;
5.显示表中的记录: Select * from 表名;
6.往表中插入记录: Insert into 表名 values("a001","000");
7.更新表中数据 : Update 表名 set 字段名1='a',字段名2='b' where PK='c';
8.用文本方式将数据装入数据表中: Load data local infile "D:/mysql.txt" into table 表名;
9.导入.sql文件命令: Use 数据库名;Source D:/mysql.sql;
10.命令行修改root密码: Update mysql.user SET password=PASSWORD('新密码')where User='root';
11.显示use的数据库名:Select Database();
12.显示当前的user: Select user();
刚才我也遇到了这个问题,还好,解决了,
估计楼主也是和我一样,在若干个
PreparedStatement preInsert.setString(..);
preInsert.setString(..);
之后来了一句:
ResultSet rs = preInsert.executeQuery();
然后执行程序就出现了上面的问题,
究其原因,因为没有弄明白Statement类以及它的子类的几个执行SQL语句
executeQuery()语句是用于产生单个结果集的语句,如select语句,在什么情况下用,当你的数据库已经保存了数据后,要进行查询了,把所有的结果放在一个集合里,这时候就用这个
executeUpdate(),用于执行insert、update或者delete语句,返回值一个表示受影响的行数,即更新值
execute()运行语句,返回是否有结果集。
解释了以上这些,可以这样解决,
PreparedStatement preInsert.setString(..);
preInsert.setString(..);
preInsert.executeUpdate(); //保存到数据库
ResultSet rs =
preInsert.executeQuery("select * from userinfo");
//打开保存的那张表,查询数据库