Example Code: Java Oracle connection test using jdbc thin

by rajesh 2012-05-24 20:01:24

Example Code: Java Oracle connection test using jdbc thin


import java.sql.*;
class Conn {
public static void main (String[] args) throws Exception
{
Class.forName ("oracle.jdbc.OracleDriver");

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/xe", "username", "password");
try {
Statement stmt = conn.createStatement();

System.out.println("Connected......");
}
finally {
try { conn.close(); } catch (Exception ignore) {}
}
}
}



In the above code replace xe with SERVICE name,
username with proper username
password with db password for that user.


Save the file in Conn.java

compile it using javac -d . Conn.java

set classpath with path to ojdbc14.jar
example: export CLASSPATH=$CLASSPATH:/usr/java/jdk1.6.0_25/lib/ojdbc14.jar

run the file "java Conn"
2003
like
1
dislike
0
mail
flag

You must LOGIN to add comments