当前位置: 技术问答>java相关
请教关于下面这段代码
来源: 互联网 发布时间:2015-11-01
本文导语: 请教关于下面这段代码,这是我在一个事件触发函数中写的,databaseip,databasename,dbpw,databasepsaaword,Uname,Unamedb,Upassword都为预定义好的全局String变量,我这段代码的意图是通过用户输入的sqlserver ip地址和sqlserver用户名,...
请教关于下面这段代码,这是我在一个事件触发函数中写的,databaseip,databasename,dbpw,databasepsaaword,Uname,Unamedb,Upassword都为预定义好的全局String变量,我这段代码的意图是通过用户输入的sqlserver ip地址和sqlserver用户名,密码,来重新连接数据库。通过输入的当前操作用户的用户名和密码,来检验操作员的密码是否正确。这段代码编译没有什么问题,可执行这后做相应的操作便会有一大堆错误?请教高手!这该如何解决?
char[] dbpw;
char[] oppw;
databaseip = jTextField36.getText();
databasename = jTextField37.getText();
dbpw = jPasswordField15.getPassword();
databasepassword = dbpw.toString();
Uname = jTextField38.getText();
Unamedb = "'" + Uname + "'";
oppw = jPasswordField16.getPassword();
Upassword = oppw.toString();
database = "jdbc:microsoft:sqlserver://" + databaseip + ":1433;DatabaseName=Bank";
database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor(database, databasename, databasepassword, false, "com.microsoft.jdbc.sqlserver.SQLServerDriver"));
if (Upassword != null)
{
String sqlres=null;
sqlstatement = "SELECT U_Password FROM Userinfo WHERE UID = " + Uname;
queryDataSet1.close();
queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, sqlstatement, null, true, Load.ALL));
sqlres = queryDataSet1.getString(0);
if (!sqlres.equals(Upassword))
{
JOptionPane.showMessageDialog(jOptionPane1, "操作密码错误!请重新输入!",
"错误", JOptionPane.ERROR_MESSAGE);
}
}
错误提示
See com.borland.dx.dataset.DataSetException error code: BASE+42
com.borland.dx.dataset.DataSetException: Operation failed. DataSet is not open.
at com.borland.dx.dataset.DataSetException.a(Unknown Source)
at com.borland.dx.dataset.DataSetException.dataSetNotOpen(Unknown Source)
at com.borland.dx.dataset.DataSet.getVariantStorage(Unknown Source)
at com.borland.dx.dataset.ReadRow.getString(Unknown Source)
at com.seu.bank.admin.Main.jButton32_actionPerformed(Main.java:1183)
at com.seu.bank.admin.Main$29.actionPerformed(Main.java:702)
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)
char[] dbpw;
char[] oppw;
databaseip = jTextField36.getText();
databasename = jTextField37.getText();
dbpw = jPasswordField15.getPassword();
databasepassword = dbpw.toString();
Uname = jTextField38.getText();
Unamedb = "'" + Uname + "'";
oppw = jPasswordField16.getPassword();
Upassword = oppw.toString();
database = "jdbc:microsoft:sqlserver://" + databaseip + ":1433;DatabaseName=Bank";
database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor(database, databasename, databasepassword, false, "com.microsoft.jdbc.sqlserver.SQLServerDriver"));
if (Upassword != null)
{
String sqlres=null;
sqlstatement = "SELECT U_Password FROM Userinfo WHERE UID = " + Uname;
queryDataSet1.close();
queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, sqlstatement, null, true, Load.ALL));
sqlres = queryDataSet1.getString(0);
if (!sqlres.equals(Upassword))
{
JOptionPane.showMessageDialog(jOptionPane1, "操作密码错误!请重新输入!",
"错误", JOptionPane.ERROR_MESSAGE);
}
}
错误提示
See com.borland.dx.dataset.DataSetException error code: BASE+42
com.borland.dx.dataset.DataSetException: Operation failed. DataSet is not open.
at com.borland.dx.dataset.DataSetException.a(Unknown Source)
at com.borland.dx.dataset.DataSetException.dataSetNotOpen(Unknown Source)
at com.borland.dx.dataset.DataSet.getVariantStorage(Unknown Source)
at com.borland.dx.dataset.ReadRow.getString(Unknown Source)
at com.seu.bank.admin.Main.jButton32_actionPerformed(Main.java:1183)
at com.seu.bank.admin.Main$29.actionPerformed(Main.java:702)
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)
|
queryDataSet1.close();
queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, sqlstatement, null, true, Load.ALL));
queryDataSet1.open();//你忘了打开DataSet
queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, sqlstatement, null, true, Load.ALL));
queryDataSet1.open();//你忘了打开DataSet
|
不需要啊!只要关闭就可以了!Cbuilder也是可以不需要的!你只要使用
SQL->SetText(_T(SQL))就行了!
SQL->SetText(_T(SQL))就行了!