用java进行对数据表的插入操作,一直提示该语句没有返回结果集
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost;integratedSecurity=true;Database=txtEditor";
Statement stmt = null;
ResultSet result = null;
Connection dbConn = null;
try {
stmt=dbConn.createStatement();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String strsql=editor.getText();
java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
System.out.println(currentDate);
String sql="SET NOCOUNT ON insert into txt (time,txt) values ('"+currentDate+"','"+strsql+"');";
try {
result = stmt.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
com.microsoft.sqlserver.jdbc.SQLServerException: 该语句没有返回结果集。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:807)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:696)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1716)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeQuery(SQLServerStatement.java:623)
at Editor.Editor$2.actionPerformed(Editor.java:228)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
网上大概搜了一遍,都说在sql语句前加上SET NOCOUNT ON ,我试了一下依然提示啊。
相关阅读:
使用angular加载数据后点击按钮添加数据无法直接显示加载出的那一条数据?
thinkphp3.1 关闭调试模式后 设置layout无效
支付宝安全采用的安全机制是什么?
为什么完整的移动端项目比较少?
微博应用在授权之前如何获取用户信息?
springboot是如何返回jsp网页的?
jetty 的日志怎么定期清理
iOS,怎么让UITableView只能下拉,到达底部后,就不能上拉.
新浪微博第三方登录 code获取access token 怎么获取?
intellij-idea执行程序时引入文件参数的路径?
求优化一个查找有序list的相同子串的算法
svn checkout下来的代码报错怎么解决
不知道为什么设置的微软雅黑字体发虚
急!!!Memcache::addserver() 最后一个参数,为什么我不管设置多少,都返回false
如何用计算机程序实现共轭梯度法?
bash中alias的命令有多层引号怎么处理
Swift用闭包实现动画问题总报错,求解决
android4.4.2 第三方应用如何删除本地短信
iOS,合并工程
iOS App服务端选用什么技术