简体   繁体   English

将MSAccess数据库与Java Web应用程序连接

[英]Connecting MSAccess database with java webapplication

I am trying to connect Msaccess database with my java webapplication using the following code: 我正在尝试使用以下代码将Msaccess数据库与Java Web应用程序连接:

    import java.sql.*;
 public class connection {
 public static void main(String[] args) {
try {
// Load MS accces driver class
 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  System.out.println("loaded");

  String url =  "jdbc:odbc:OnboardingTT";

   System.out.println("assigned");
  // specify url, username, pasword - make sure these are valid 
   Connection conn = DriverManager.getConnection(url,"","");

   System.out.println("Connection Succesfull");

  } catch (Exception e) {
 System.err.println("Got an exception! ");
  System.err.println(e.getMessage());


    }}}

But connection is not established. 但是没有建立连接。 and the error is 错误是

    loaded 
    assigned
  Got an exception!
    null   
    java.lang.NullPointerException      
    at sun.jdbc.odbc.JdbcOdbcDriver.initialize(Unknown Source) at
    sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source) at  
    java.sql.DriverManager.getConnection(Unknown Source) at 
    java.sql.DriverManager.getConnection(Unknown Source) at   
    connect.connection.main(connection.java:18)

I also tried with 我也尝试过

 String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb,*.accdb)};DBQ="+ "C:\\OnboardingTT.mdb";

Is this code correct or i have to do any changes in this please answer my question 此代码是否正确,或者我必须对此进行任何更改,请回答我的问题

Looks like something went wrong with the DB connection, maybe the DB is not online, maybe the user or the password are incorrect... 数据库连接似乎出了点问题,也许数据库未在线,也许用户或密码不正确...

Please provide more info to help us to help you. 请提供更多信息,以帮助我们为您提供帮助。

;-) ;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM