MS Access database connection problem
Please help me to find out the problem with my code. I don't find exactly where the problem is. I am just trying to create a database connection and make a table. I am using MS Access.
Code :
import java.sql.*;
/**
*
* @author Faysal
*/
public class dConnection {
public dConnection() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.accdb)}; DBQ=Data.accdb;";
Connection c = DriverManager.getConnection(database, "", "");
Statement st = c.createStatement();
String tName = "Student";
String cTable = "CREATE TABLE " + tName +
"(id Integer, name Text(32), school Text(32), class Text(15), roll Text(10), "
+ "phone Text(20), address(32))";
st.execute(cTable);
st.close();
c.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
Re: MS Access database connection problem
you have 2 errors
* your driver is wrong
Code java:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection c= DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D://Data.accdb;PWD=yourpassword;");
* and you have Syntax error you didn't write type of address field