How to test Oracle connection via JDBC Thin driver.
SCOPE: Oracle JDBC Connection Test
PURPOSE: All documents are provided on this Blog just for educational purposes only. Please make sure that you run it in your test environment before to move on to production environment.
STEP 1.
Create a file OracleCon.java with the following code.
vi OracleCon.java
import java.sql.*;
public class
OracleCon
{
public static void
main(String args[])
throws
ClassNotFoundException, SQLException
{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@ ORADBPRD.th.com:1521:KARDBPRD";
Connection conn =
DriverManager.getConnection(url,"user_tst01","pw_xyz");
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
ResultSet
rs=stmt.executeQuery("select user from dual;");
while(rs.next())
{
System.out.println (rs.getString(1));
}
stmt.close();
System.out.println ("Connection
succeeded");
}
}
STEP 2.
Compile the code.
Execute the program
as follow.
Connection succeeded
No comments:
Post a Comment