jdbc ucanaccesssqlexception ucaexc ::: 4.0 4 unexp

2020-05-10 04:01发布

问题:

I am using netbeans with java classes to fetch data from access database tables and display it on jtable. When I followed all the steps it gives me the ucanaccess error as net ucanaccess jdbc ucanaccesssqlexception ucaexc ::: 4.0 4 unexpected token: DOCTOR. i have two tables in accdb called Patient and Doctor.

I have done everything needed for it.

public void viewAppointment() throws ClassNotFoundException, SQLException{    
   Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");     
   Connection conn = DriverManager.getConnection("jdbc:ucanaccess://C:/Users/AQ/Documents/NetBeansProjects/MC170402106_2/MC170402106.accdb");     
   String sql1 = "Select p.Name AS Patient, p.Disesae AS Disease, Doctor.Name AS Doctor"
           + " Doctor.Visiting_Day AS SechduleDay from Patients AS p"
           + " where p.Disease = Doctor.Specialization";     
   try{     
       ps = conn.prepareStatement(sql1);     
       rs = ps.executeQuery();      
       jTable1.setModel(DbUtils.resultSetToTableModel(rs));     
   }          
   catch(Exception e){         
       JOptionPane.showMessageDialog(null, e);       
   }        

I expect that this will take data from database and display it on jtable.

回答1:

I assume:

  1. you are using JPA
  2. you set delimited-identifiers
  3. you also are using EclipseLink as implementation.

If so, do as follows:

Include a target-database entry in persistence.xml:

    <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.AccessPlatformDelimiterConfig"/>

Add a new class to your classpath:

package org.eclipse.persistence.platform.database;

public class AccessPlatformDelimiterConfig extends AccessPlatform {

    private static final long serialVersionUID = 7034590043310425678L;

    public AccessPlatformDelimiterConfig() {
        super();
        this.tableQualifier = "";
        this.startDelimiter = "";
        this.endDelimiter = "";
    }
}