我收到一些有关从ms访问数据库中检索数据的问题

时间:2016-10-23 14:10:50

标签: java resultset ms-access-2013 ucanaccess

我正在尝试从数据库中检索数据,但我遇到了一些问题。 这是我的代码:

  {
        try
         {
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://F:\\Realestate\\real estate.accdb");
Statement st=conn.createStatement();
String sql="select Property type,Property owner from property where Property type='"+searchbyidfld.getText()+"'and Property owner='"+searchbynamefld.getText()+"'";
ResultSet rs=st.executeQuery(sql);
if(rs.next())
{
  String retrieve=rs.getString("Property type");
  System.out.println(retrieve);
 }
  }
catch(Exception ex)
 {
   JOptionPane.showMessageDialog(null,"No record found");                                           
   }
   }

我还在URL中提供了数据库的正确路径。 这是我试图检索数据的数据库enter image description here 我不知道我做错了什么。

这是堆栈跟踪:

net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.6 user lacks privilege or object not found: PROPERTY
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.6 user lacks privilege or object not found: PROPERTY
    at net.ucanaccess.jdbc.UcanaccessStatement.executeQuery(UcanaccessStatement.java:211)
    at real.estate.Loginbtn$4$27$9$11.actionPerformed(Loginbtn.java:1691)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    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:6535)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6300)

1 个答案:

答案 0 :(得分:3)

在您的代码String sql="select [Property type],[Property owner] from property where [Property type]='"+searchbyidfld.getText()+"'and [Property owner]='"+searchbynamefld.getText()+"'";中尝试此操作 包含空格的列名应该用方括号括起来。我希望这对你来说很好用