Add

Java Program for Creating Connection with database in JDBC.

11:51:00 PM Rohit Kumar Verma 0 Comments

Prequiste:
DataBase: oracle any version: Tested with Oracle 12c
Java: Any Version below 7.0: Tested in Java 7.0, From 8.0 JDBC Removed.


//ConnTest.java
import java.sql.*;
public class ConnTest
{
public static void main(String args[])
{
try{
//registering jdbc driver
// Creating jdbc driver object
sun.jdbc.odbc.JdbcOdbcDriver obj = new sun.jdbc.odbc.JdbcOdbcDriver();
DriverManager.registerDriver(obj);
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn","c##scott","tiger");
if(con==null)
{
System.out.println("Connection is not Established");
}
else
{
System.out.println("Connection Established");
}
}
catch ( SQLException se)
{
System.out.println("Invalid UserName and password");
}
}//Main
}//Class

0 comments: