Sandeep & Vicky’s Archive ยป Blog Archive » How to connect to access database in java without a DSN
21
Nov

How to connect to access database in java without a DSN

   Posted by: admin   in java

Hi,

The following code connects to an access database “multilingual.mdb” located in the default folder of the java code. It does not requires to create a dsn for the same

CODE

try
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
String myDB = “jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=multilingual.mdb”;
Connection c = DriverManager.getConnection(myDB,”",”");

Statement s=c.createStatement();

ResultSet rss=s.executeQuery(“select naam from table1 where id=1″);

rss.next();
String st=rss.getString(1);

System.out.println(“string=”+st);
}
catch (Exception ex)

{
ex.printStackTrace();
}

Related Posts with Thumbnails
This entry was posted on Saturday, November 21st, 2009 at 2:53 pm and is filed under java. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment