我正在使用 Netbeans
8.0.2用于gui创建和
MYSQL Query Browser
对于数据库。有一个 JInternalFrame
调用的窗体 LCI
在我的java项目和该接口中,我有一个名为 DATE
和一个 JButton
打电话 Load_To_Table
。我需要从名为 LCI
我已经创建并与项目相连接。
首先,用户必须从中选择一个日期 DATE
然后单击 Load_To_Table
. 然后应用程序应该检查是否有一个与 DATE
如果是这样,它应该将该记录检索到 JTable
打电话 tb1
.
下面是我的代码。
private void Load_To_TableActionPerformed(java.awt.event.ActionEvent evt) {
try{
Statement s = DB.getConnection().createStatement();
DefaultTableModel dtm=(DefaultTableModel)tb1.getModel();
Vector v=new Vector();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ResultSet rs,rs1,rs2,rs3,rs4,rs5;
rs1=j.getData("select E_ID from User where E_ID='"+user+"'");
if(rs1.next()==true)
{
rs=j.getData("select * from LCI where L_DATE= '"+dateFormat.format(DATE.getDate())+"'");
if(rs.next()== true)
{
v.add(rs.getString("L_ID"));
v.add(rs.getString("HEADING"));
v.add(rs.getString("INSTITUTE"));
v.add(rs.getString("L_DATE"));
JOptionPane.showMessageDialog(this, "Successful");
}
else
{
System.out.println(rs.getString("L_DATE"));
JOptionPane.showMessageDialog(this, "There is no data related to the date you entered.Please try another date.");
}
}
else{
JOptionPane.showMessageDialog(this, "Failed to connect with DB. Please try again");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
// TODO add your handling code here:
}
但它给出了一个错误,表示它是非法操作或空操作 result set
.
下面是堆栈跟踪。
java.sql.SQLException: Illegal operation on empty result set.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:855)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5773)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5693)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5733)
at Viewer.LCI.Load_To_TableActionPerformed(LCI.java:668)
at Viewer.LCI.access$800(LCI.java:25)
at Viewer.LCI$9.actionPerformed(LCI.java:342)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6516)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6281)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:706)
at java.awt.EventQueue$3.run(EventQueue.java:704)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:720)
at java.awt.EventQueue$4.run(EventQueue.java:718)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
BUILD SUCCESSFUL (total time: 8 minutes 7 seconds)
谁能告诉我应该如何修改代码来完成我在本说明第二段中所描述的(检索与用户输入的日期相符的数据)。提前谢谢。
暂无答案!
目前还没有任何答案,快来回答吧!