1
votes

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
In your catch block, please could you try adding ex.printStackTrace(); so we can see any errors? - Simon Nickerson
(Post edit): Your error message looks crazy! Is the database configured to use a non-Latin alphabet? If so, is your console set up to display this text properly? - Simon Nickerson
well i tried to make a database from data source in order to save my access database...i found a trick to do that in C:\\windows\syswow64\odbca32 but when i try to have access to the db i create it fails..i believe its the connection problem but i cant solve it.. :/ - Nomik

1 Answers

0
votes

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"