4 Types of JDBC Drivers
4 Types of JDBC Drivers
4 Types of JDBC Drivers
5. Then...
Insert your own Data Source Name and click on Select button.
6. Then...
Choose your Database Access file like above and click OK button.
*** note: before these procedures, we must have Database Access file.
We can make this file by using MS Access .
This Access file should have a table named by tb_address.
import java.sql.*;
int i;
Connection conn = null;
// connect to DB
try{
conn = DriverManager.getConnection("jdbc:odbc:my_database");
} catch(SQLException se) {
System.out.println(se);
}
System.out.println("connection is successful!!!");
try{
String selectSQL = "select ID, NAME, ADDRESS from tb_address";
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery(selectSQL);
while(rset.next()){
System.out.println("ID: " + rset.getString(1) + " NAME: " +
rset.getString(2) + " ADDRESS:" +
rset.getString(3));
}
stmt.close();
} catch(SQLException se) {
System.out.println(se);
}
}
import java.sql.*;
int i;
Connection conn = null;
} catch(ClassNotFoundException e) {
System.out.println(e);
}
// connect to DB
try{
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:datacafe",
"scott","tiger");
// thin: driver
// @127.0.0.1 for local connection. @xxx.xxx.xxx.xxx for global
// 1521: port number. This should be match to Oracle network port.
// datacafe: SID of Oracle database
// scott: username of Oracle database
// tiger: password of Oracle database
} catch(SQLException se) {
System.out.println(se);
}
System.out.println("connection is successful!!!");
try{
String selectSQL = "select ID, NAME, ADDRESS from tb_address";
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery(selectSQL);
while(rset.next()){
System.out.println("ID: " + rset.getString(1) + " NAME: " +
rset.getString(2) + " ADDRESS:" +
rset.getString(3));
}
stmt.close();
} catch(SQLException se) {
System.out.println(se);
}
}