Mr.s Mr.s - 1 month ago 11
Java Question

I am getting some issues regarding retrieving data from ms access database

I am trying to retrieve data from database but i am getting some issues.
Here is my code:

{
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");
}
}


I also provided right path of the database in the URL.
Here is my database from where i am trying to retrieve dataenter image description here
I don't know what i am doing wrong.

here is the stack trace:

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)

Answer

try this in your code String sql="select [Property type],[Property owner] from property where [Property type]='"+searchbyidfld.getText()+"'and [Property owner]='"+searchbynamefld.getText()+"'"; column names containing spaces should be enclosed in square brackets.I hope this will work fine for you

Comments