当前位置: 技术问答>java相关
关于jbuilder中querydataset查询数据库的问题
来源: 互联网 发布时间:2015-11-03
本文导语: 下面这段代码的意图是验证登陆,通过读取jTextField38和jPasswordField16中的输入,然后来验证密码的正确与否, char[] oppw; String Uname = jTextField38.getText(); String Unamedb = "'" + Un...
下面这段代码的意图是验证登陆,通过读取jTextField38和jPasswordField16中的输入,然后来验证密码的正确与否,
char[] oppw;
String Uname = jTextField38.getText();
String Unamedb = "'" + Uname + "'";
oppw = jPasswordField16.getPassword();
String Upassword = new String(oppw);
String 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));
queryDataSet1.open();
String sqlres = queryDataSet1.getString(1); //数据库中存储的该id的密码
System.out.println(sqlres); //这是我后来加的,本意是显示数据库返回的密码,可惜执行时 //报错,无法达到预期效果。
if (!sqlres.equals(Upassword)) //密码比较
{
JOptionPane.showMessageDialog(jOptionPane1, "操作密码错误!请重新输入!",
"错误", JOptionPane.ERROR_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(jOptionPane1, "恭喜!您已经成功登陆本系统!",
"成功", JOptionPane.INFORMATION_MESSAGE);
}
错误提示:
See com.borland.dx.dataset.DataSetException error code: BASE+66
com.borland.dx.dataset.DataSetException: [Microsoft][SQLServer 2000 Driver for JDBC]Unable to connect. Invalid URL.
at com.borland.dx.dataset.DataSetException.a(Unknown Source)
at com.borland.dx.dataset.DataSetException.throwException(Unknown Source)
at com.borland.dx.dataset.DataSetException.SQLException(Unknown Source)
at com.borland.dx.sql.dataset.Database.openConnection(Unknown Source)
at com.borland.dx.sql.dataset.Database.createPreparedStatement(Unknown Source)
at com.borland.dx.sql.dataset.o.a(Unknown Source)
at com.borland.dx.sql.dataset.o.d(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.jButton32_actionPerformed(Main.java:1318)
at com.seu.bank.admin.Main$39.actionPerformed(Main.java:777)
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]Unable to connect. Invalid URL.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.borland.dx.sql.dataset.Database.openConnection(Unknown Source)
at com.borland.dx.sql.dataset.Database.createPreparedStatement(Unknown Source)
at com.borland.dx.sql.dataset.o.a(Unknown Source)
at com.borland.dx.sql.dataset.o.d(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.jButton32_actionPerformed(Main.java:1318)
at com.seu.bank.admin.Main$39.actionPerformed(Main.java:777)
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[] oppw;
String Uname = jTextField38.getText();
String Unamedb = "'" + Uname + "'";
oppw = jPasswordField16.getPassword();
String Upassword = new String(oppw);
String 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));
queryDataSet1.open();
String sqlres = queryDataSet1.getString(1); //数据库中存储的该id的密码
System.out.println(sqlres); //这是我后来加的,本意是显示数据库返回的密码,可惜执行时 //报错,无法达到预期效果。
if (!sqlres.equals(Upassword)) //密码比较
{
JOptionPane.showMessageDialog(jOptionPane1, "操作密码错误!请重新输入!",
"错误", JOptionPane.ERROR_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(jOptionPane1, "恭喜!您已经成功登陆本系统!",
"成功", JOptionPane.INFORMATION_MESSAGE);
}
错误提示:
See com.borland.dx.dataset.DataSetException error code: BASE+66
com.borland.dx.dataset.DataSetException: [Microsoft][SQLServer 2000 Driver for JDBC]Unable to connect. Invalid URL.
at com.borland.dx.dataset.DataSetException.a(Unknown Source)
at com.borland.dx.dataset.DataSetException.throwException(Unknown Source)
at com.borland.dx.dataset.DataSetException.SQLException(Unknown Source)
at com.borland.dx.sql.dataset.Database.openConnection(Unknown Source)
at com.borland.dx.sql.dataset.Database.createPreparedStatement(Unknown Source)
at com.borland.dx.sql.dataset.o.a(Unknown Source)
at com.borland.dx.sql.dataset.o.d(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.jButton32_actionPerformed(Main.java:1318)
at com.seu.bank.admin.Main$39.actionPerformed(Main.java:777)
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]Unable to connect. Invalid URL.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.borland.dx.sql.dataset.Database.openConnection(Unknown Source)
at com.borland.dx.sql.dataset.Database.createPreparedStatement(Unknown Source)
at com.borland.dx.sql.dataset.o.a(Unknown Source)
at com.borland.dx.sql.dataset.o.d(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.jButton32_actionPerformed(Main.java:1318)
at com.seu.bank.admin.Main$39.actionPerformed(Main.java:777)
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)
|
你的database1应该先调用database1.setconnection(......);
|
[Microsoft][SQLServer 2000 Driver for JDBC]Unable to connect. Invalid URL.
很明显数据库没有联接成功
可能是jdbc有错误
或者url有错误
很明显数据库没有联接成功
可能是jdbc有错误
或者url有错误