import java.sql.*;
class dbAccess {
public static void main (String args []) throws SQLException
{
Connection con=null;
try {
Class.forName ("oracle.jdbc.driver.OracleDriver");
System.out.println("Driver loaded successfully");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:dsn","scott","tiger");
// @machineName:port:SID, userid, password
System.out.println("connection established");
Statement db_statement = con.createStatement();
// Create a simple table, which stores an employee ID and name
db_statement.executeUpdate("create table employee( empid varchar2(5), firstname varchar2(10), salary number(7))");
// Insert an employee, so the table contains data
db_statement.executeUpdate("insert into employee values('1234','JohnDoe',1234567)");
// Execute query
ResultSet result = db_statement.executeQuery("select * from employee");
// While more rows exist, print them
while (result.next() )
{
// Use the getInt method to obtain emp. id
System.out.println ("ID : " + result.getString("empid"));
// Use the getString method to obtain emp. name
System.out.println ("Name : " + result.getString("firstname"));
System.out.println ("Salary : " + result.getInt("salary"));
//System.out.println ();
}
// Commit changes
//con.commit();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}