//JAVA SNIPPET FOR MS-ACCESS DB CONNECTIVITY
public class DataBaseConnection {
Statement stmt;
Connection con;
ResultSet rs;
String url;
public Connection connect()throws ClassNotFoundException,SQLException
{
// Step 1. Load the Type 1 database driver:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// Step 2. Create a connection to the database
// using pre-defined Data Source:
File f=new java.io.File("c:/Train.accdb");
if(f.exists())
url= "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" +f.getPath();
else
url= "jdbc:odbc:Train";
con = DriverManager.getConnection(url,"","");
return con!=null ? con:null;
}
public void close() throws SQLException{
con.close();
}
}
Click below to download code JAVA BEAN
No comments:
Post a Comment