steps of connection database access whit java:
1_build database:
2_making odbc for database access:
**go to control panel>>administrative tools>> Data Sources
(ODBC)>>System Dsn>>click button ADD>>choose Microsoft access
driver>>choose select in database panel>>choose your database which you
built>>set any name for data source name>>press ok.
example select statement:
import java.sql.*;
class Test_select {
public static void main(String[] args) {
Connection c = null;
Statement s = null;
ResultSet r = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c = DriverManager.getConnection("jdbc:odbc:db_test","","");
s = c.createStatement();
r = s.executeQuery("select * from test");
while(r.next())
{
System.out.println("name is "+ r.getString("name") +"and age is "+r.getInt("age"));
}}
catch(Exception e1){
System.out.println(e1);}
} }
example update statement:
Connection c = null;
Statement s = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c = DriverManager.getConnection("jdbc:odbc:db_test","","");
PreparedStatement stat = c.prepareStatement("UPDATE
test SET name=’mazen’ WHERE st_id=3");
stat.execute();
} catch (Exception ex) {
System.out.println("Error adding " + ex.toString());
}
example insert statement:
Connection c = null;
Statement s = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c = DriverManager.getConnection("jdbc:odbc:db_test","","");
PreparedStatement stat = c.prepareStatement("insert
into test(name,age) values(?,?)");
stat.setString(1,’khaled’);
stat.setString(2,’smeer’);
stat.execute();
} catch (Exception ex) {
System.out.println("Error adding " + ex.toString());
}
All that done by omar abdo