First of all find your drivers, mine were located in <DRIVE>:\Oracle\Ora81\jdbc\lib\classes12.zip, and add them to your classpath so you can reference them in the import statements
Next, register the driver using the statement using:
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Then define the connection by using:
String url =
jdbc racle:TYPE:@DATABASE_NAME;
/**Replace TYPE with either 'thin' or 'oci8' depending on the driver that you're wanting to use. They both have different pro's and con's depending on what you are using them for. You can find more info at oracle.com. Replace the database name with the name of the database in the TSNNAMES file that you need to access. If you need to access the database remotely, then replace it with url(or ip) :port:SID. Ex. 127.0.0.1:1521:MYDATABASE (1521 is the default port for Oracle) and next.....*/
String username = your_username;
String password = your_password;
/**that one's easy, they are just your username and password for that database, then finally....*/
Connection con = DriverManager.getConnection(url, username, password);
/**this creates the connection object and you are now connected to the database of your choice*/
After you have the connection you need to create your statement object:
Statement stmt = con.createStatement();
Then use these to execute the SQL statements:
stmt.executeUpdate(Your_Update_String);
or stmt.execute(Your_String);
or stmt.executeQuery(Your_Query_String);
JDBC commits the data automaticaly so if you need or want to commit transaction manually then you can set the auto commit to false before you create the statement using:
con.setAutoCommit(false)
and after your transaction is complete you can commit it by using con.commit() and if the SQL statement fails you can place a con.rollback() in your catch statement to roll back any partial changes to the data.
Hope that helps out.
Disabled smiles in this post [This message has been edited by Desai Sandeep (edited November 30, 2001).]