gpt4 book ai didi

java - 在java中获取第一个记录表单数据库?

转载 作者:搜寻专家 更新时间:2023-10-30 23:11:31 25 4
gpt4 key购买 nike

我创建了一个 java 类,我想从数据库中获取第一条记录,我正在使用查询来获取它,但它不工作并给出了一些异常。

使用这段代码:

else if(ae.getSource()==btnfirst)
{
try{
m.rs=m.st.executeQuery("Select * from purchase ");
m.rs.first();

inv=m.rs.getInt(1);
String inv1=Integer.toString(inv);

int qty2=m.rs.getInt(5);
String qty1=Integer.toString(qty2);

rate=m.rs.getInt(6);
String rate1=Integer.toString(rate);

txtinvoice1.setText(inv1);
txtdate1.setText(m.rs.getString(2));
txtparty1.setText(m.rs.getString(3));
ctrucktype1.setSelectedItem(m.rs.getString(4));
txtcalu1.setText(qty1);
txtrate1.setText(rate1);
txtbuilty1.setText(m.rs.getString(7));

}catch(Exception e)
{e.printStackTrace();}
}

在使用限制 1 堆栈跟踪后给出

H:\Workspace\Mining Inventory\Project\src>java mdiform
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in
FROM clause.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3109)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:337)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:2
52)
at PurchaseMaster.actionPerformed(PurchaseMaster.java:307)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:20
18)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259
)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
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:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)

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

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

最佳答案

如果您只需要先记录您的查询应该是:

Select * from purchase LIMIT 1

你应该从数据库中询问比你需要的更多的东西,因为结果需要时间来找你。

编辑:因为您可能使用 Oracle,您应该试试这个:

SELECT * FROM purchase WHERE ROWNUM = 1

此外,您还需要在 WHERE 中指定一些特定内容,因为限制可以帮助您仅获得一个结果,但如果您不指定任何条件,则不太可能获得您想要的结果。

关于java - 在java中获取第一个记录表单数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19404623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com