java.sql.SQLException: Can not issue data manipulation statements with executeQuery().解决办法

数据库JDBC的常见问题

1.excuteUpate和excuteQuery的常见用法错误

 Result excuteQuery() ;//执行的是查询功能,返回值是Result对象

如果是用于添加,使用该语句的话会报错的;
java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:413)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1821)
at com.itheima.test.testPool.main(testPool.java:19)

int executeUpdate();//执行的是添加功能insert into,,执行的sql语句。但是sql语句是没有返回值的;
String sql="insert into user values(null,'zhu',123456)";
		 ps=conn.prepareStatement(sql);
		 ps.executeUpdate();

总结:executeUpdate: 是用于没有返回值的的SQL语句
executeQuery:是用于查询的语句

发布了3 篇原创文章 · 获赞 0 · 访问量 23

猜你喜欢

转载自blog.csdn.net/weixin_42861101/article/details/104400564