Connecting to Access Database using Type-1 Driver in java
java programming and c, c++, Matlab, Python, HTML, CSS programming language, and new techniques news and any history.
2-Go to Administrative tools
3-Select Data Source(ODBC)
4-Add new DSN name, select add
5-Select Access driver from the list, click on finish
6-Give a DSN name, click ok
java programming and c, c++, Matlab, Python, HTML, CSS programming language, and new techniques news and any history.
Connecting to Access Database using Type-1 Driver
To connect a Java application with Access database using JDBC-ODBC Bridge(type-1) Driver. You need to follow the following steps createCreate DSN Name
2-Go to Administrative tools
3-Select Data Source(ODBC)
4-Add new DSN name, select add
5-Select Access driver from the list, click on finish
6-Give a DSN name, click ok
NOTE: Here we are showing this example to create DSN in Window 7 os. For another operating system, you need to do small changes.
Example
We suppose that you have created a student table with sid and name column name in an access database.
import java.sql.*; class Test { public static void main(String []args) { try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:Test", "", ""); Statement s=con.createStatement(); //creating statement ResultSet rs=s.executeQuery("select * from student"); //executing statement while(rs.next()){ System.out.println(rs.getInt(1)+" "+rs.getString(2)); } con.close(); //closing connection }catch(Exception e) { e.printStackTrace(); }
}
}
Comments
Post a Comment