General discussion


java & oracle

By sudeep.nigam ·
how to connect java with oracle database

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by rlee In reply to java & oracle
Collapse -

by kadsoft In reply to java & oracle

import java.sql.*;

public class MyConnection {

* You need the oracle's driver jar (classes12.jar)
public static void main(String args[]) {
try {
//Attempts to establish a connection to the given database URL.
//The DriverManager attempts to select an appropriate driver from
//the set of registered JDBC drivers.
Connection myConn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:MYDATABASE", "user", "password");

//Creates a Statement object for sending
//SQL statements to the database.
Statement myStatement = myConn.createStatement();

//Executes the given SQL statement, which returns a single ResultSet object.
ResultSet myResultSet = myStatement.executeQuery("SELECT * FROM table");

//Iterates the resultSet so you can get the info
while ( {
//close the ResultSet object

//Releases this Connection object's database and JDBC resources
//immediately instead of waiting for them to be automatically released.
catch (ClassNotFoundException cnfex) {
System.err.println("Can't load JDBC");
catch (SQLException sqlex) {
System.err.println("No connection");


Collapse -

by rajesh_m_vaghela In reply to java & oracle

put oracle\ora92\lib\classes12.jar in your java application classpath. then load JDBC Driver

user below url to connect database
url = jdbc:oracle:thin:@Hostname:Portnumber:Databasename
Connection c = DriverManager.getConnect(url).

I think this is enough

Related Discussions

Related Forums