UCanAccess连接上的“无效授权规范”错误

问题描述 投票:2回答:2

我的UCanAccess驱动程序有问题,即当我尝试使用以下代码连接到数据库时

public static void main(String[] args) {
    //establish connection with database in order to execute sql queries
    try {
        conn = DriverManager.getConnection("jdbc:ucanaccess://H:\\IT_PAT_Program_LOCALONLY\\IT_Pat_Database.accdb;showschema=true");
        System.out.println("Connection Established");
    } catch (SQLException ex) {
        System.out.println("Could Not Connect to database\n"+ex);
    }
    //closes the database connection at program shutdown
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            try {
                conn.close();
                System.out.println("Shutdown Succesful");
            } catch (SQLException ex) {
                System.out.println("An exception occured\n"+ex);
            }
        }
    });
}

我遇到以下错误:

Could Not Connect to database
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.0 invalid authorization specification - not found: Admin

数据库也作为持久性单元进行连接,但是由于我不知道在代码中使用任何方法来使用它(Google一直没有帮助,所以该方法似乎是我唯一的选择。

java ms-access netbeans ucanaccess persistence-unit
2个回答
0
投票

我们在代码中看不到您在哪里进行授权。


0
投票
    Connection con;
    PreparedStatement pst;
    ResultSet rs;

    try{
        Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
        con = DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\Zairah\\Documents\\SampleDb.accdb");

        String sql = "select * from UserInfo where Username = '"+user.getText() + "' and Password='"+pass.getText()+"'";
        pst = con.prepareStatement(sql);
        rs = pst.executeQuery();
        if(rs.next()){
            welcome w = new welcome();
            w.setVisible(true);
            setVisible(false);
        }
        else{
            JOptionPane.showMessageDialog(null, "Invalid Username or Password");  
        }
    }
    catch(HeadlessException | ClassNotFoundException | SQLException e){
        JOptionPane.showMessageDialog(null, e);
    }
© www.soinside.com 2019 - 2024. All rights reserved.