Why netbeans cant see the database drive i create?

751 views Asked by At

Well i am creating a db with ms access and i add this db on Data source on odbca32..but when i create the connection i cant see whats inside the table i create...heres the code..

import java.sql.*;


 public class db {

Connection con;
Statement st;
ResultSet rs;
public db(){
connect();
}
public void connect(){

try{

    String driver="sun.jdbc.odbc.JdbcOdbcDriver";
    Class.forName(driver);

    String db="jdbc:odbc:db"; 
    con=DriverManager.getConnection(db); 
    st=con.createStatement();
    String sql="select * from Table1";
    rs = st.executeQuery(sql);

    while(rs.next()){

        String fname=rs.getString("Fname");
        String lname=rs.getString("Lname");

        System.out.println(fname+"  "+lname);

    }

}catch(Exception ex){

}
 }
public static void main(String[] args) {
    new db();
}
}

and thats the errors i got...

java.sql.SQLException: [Microsoft][?????????? ???????????? ???????? ODBC] ?? ??????????? DSN ???????? ????????? ?????????????? ?????? ??? ???????????? ???????? ??? ??? ????????? at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6964) at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7121) at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3080) at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323) at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:233) at db.connect(db.java:20) at db.(db.java:10) at db.main(db.java:39)

1

There are 1 answers

1
Simon Nickerson On BEST ANSWER

My best guess from your crazy error message is that your connection string is not right. For an MS Access database, the connection string needs to contain (at the minimum) the filename.

According to another answer on StackOverflow, you'd need something like this:

String db = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=databasefile.mdb"