当前位置:  技术问答>java相关

用queryDateSet插入数据的问题?在线急等!!!!!!!!!!!!!

    来源: 互联网  发布时间:2015-11-04

    本文导语:  我用下面这段代码意图是插入一条记录,并用另一条语句返回刚刚插入的语句的No(自动编号的),可是结果是数据能够成功插入到数据库中,但无法返回No值?如何解决?  String newaccount; String newnamedb = "'" + newnam...

我用下面这段代码意图是插入一条记录,并用另一条语句返回刚刚插入的语句的No(自动编号的),可是结果是数据能够成功插入到数据库中,但无法返回No值?如何解决? 
String newaccount;
String newnamedb = "'" + newname + "'";
String newsexdb = "'" + newsex + "'";
String newaddredb = "'" + newaddre + "'";
String newpassworddb = "'" + newpassword + "'";
newaccount = "INSERT Account (Name, ID, Sex, Address, Telephone, O_Date, O_UID, Password, Total, M_Interest, M_Date, M_UID, Loss, L_Date, L_UID) VALUES ("+ newnamedb + ", " + newid + ", " + newsexdb + ", " + newaddredb + ", " + newtel + ", getdate(), " + Unamedb + ", " + newpassworddb + ", 0, 0, getdate(), "+ Unamedb + ", 0, getdate(), " + Unamedb + ")";

queryDataSet1.close();
queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, newaccount, null, true, Load.ALL));
queryDataSet1.open();

String newaccountidsql = "SELECT No FROM Account WHERE ID = " + newid;
queryDataSet1.close();
queryDataSet1.empty();
queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, newaccountidsql, null, true, Load.ALL));
queryDataSet1.open();
String sqlresno = queryDataSet1.getString(1);
String newaccountno = "您的账号为 " + sqlresno + "。请记好!";

JOptionPane.showMessageDialog(jOptionPane1, newaccountno,
                            "成功", JOptionPane.INFORMATION_MESSAGE);
出错为:
See com.borland.dx.dataset.DataSetException error code:  BASE+62

com.borland.dx.dataset.DataSetException: Execution of query failed.

at com.borland.dx.dataset.DataSetException.a(Unknown Source)

at com.borland.dx.dataset.DataSetException.queryFailed(Unknown Source)

at com.borland.dx.sql.dataset.QueryProvider.a(Unknown Source)

at com.borland.dx.sql.dataset.JdbcProvider.provideData(Unknown Source)

at com.borland.dx.dataset.StorageDataSet.a(Unknown Source)

at com.borland.dx.dataset.DataSet.a(Unknown Source)

at com.borland.dx.dataset.DataSet.open(Unknown Source)

at com.seu.bank.admin.Main.jButton1_actionPerformed(Main.java:1257)

at com.seu.bank.admin.Main$3.actionPerformed(Main.java:330)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5093)

at java.awt.Component.processEvent(Component.java:4890)

at java.awt.Container.processEvent(Container.java:1566)

at java.awt.Component.dispatchEventImpl(Component.java:3598)

at java.awt.Container.dispatchEventImpl(Container.java:1623)

at java.awt.Component.dispatchEvent(Component.java:3439)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)

at java.awt.Container.dispatchEventImpl(Container.java:1609)

at java.awt.Window.dispatchEventImpl(Window.java:1585)

at java.awt.Component.dispatchEvent(Component.java:3439)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

Chained exception:

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]No ResultSet set was produced.

at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)

at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)

at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)

at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)

at com.borland.dx.sql.dataset.o.f(Unknown Source)

at com.borland.dx.sql.dataset.QueryProvider.e(Unknown Source)

at com.borland.dx.sql.dataset.JdbcProvider.provideData(Unknown Source)

at com.borland.dx.dataset.StorageDataSet.a(Unknown Source)

at com.borland.dx.dataset.DataSet.a(Unknown Source)

at com.borland.dx.dataset.DataSet.open(Unknown Source)

at com.seu.bank.admin.Main.jButton1_actionPerformed(Main.java:1257)

at com.seu.bank.admin.Main$3.actionPerformed(Main.java:330)

at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)

at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)

at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)

at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)

at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

at java.awt.Component.processMouseEvent(Component.java:5093)

at java.awt.Component.processEvent(Component.java:4890)

at java.awt.Container.processEvent(Container.java:1566)

at java.awt.Component.dispatchEventImpl(Component.java:3598)

at java.awt.Container.dispatchEventImpl(Container.java:1623)

at java.awt.Component.dispatchEvent(Component.java:3439)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)

at java.awt.Container.dispatchEventImpl(Container.java:1609)

at java.awt.Window.dispatchEventImpl(Window.java:1585)

at java.awt.Component.dispatchEvent(Component.java:3439)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)


|
SQL中的字符应该用单引号括起来,例如:
"SELECT * FROM table WHERE Name = '" + name + "'"
                                 ——         ——

    
 
 

您可能感兴趣的文章:

 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3