Oracle database connection



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* ORACLE DataBase Connection */

import java.sql.*;

class OracleConnection 
{
        public static void main(String[] rk) 
        {
   
  try
  {
                 System.out.println("connecting...");
         //DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  
                 Class.forName("oracle.jdbc.driver.OracleDriver");
       System.out.println("Loading Loaded Successfully...."); 

                 Connection conn = DriverManager.getConnection
 ("jdbc:oracle:thin:@192.168.100.10:1521/Stud10g", "kirpal", "kirpal");       
                 System.out.println("Connection done Successfully......");
       Statement stmt


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* ORACLE DataBase Connection */

import java.sql.*;

class OracleConnection 
{
        public static void main(String[] rk) 
        {
   
  try
  {
                 System.out.println("connecting...");
         //DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  
                 Class.forName("oracle.jdbc.driver.OracleDriver");
       System.out.println("Loading Loaded Successfully...."); 

                 Connection conn = DriverManager.getConnection
 ("jdbc:oracle:thin:@192.168.100.10:1521/Stud10g", "kirpal", "kirpal");       
                 System.out.println("Connection done Successfully......");
       Statement stmt=conn.createStatement(); 
                 String query="select * from contacts";  
       ResultSet rs=stmt.executeQuery(query);   
                 System.out.println("Query Executed Successfully.....");
   
   while(rs.next())
   {        
    System.out.println("Name : "+rs.getString(1));
   }
      

  }catch(Exception e)
  {
                  System.out.println("Error : "+e);
  }
        }

}


/*
Note : 
 Download the required version of driver and place it into the below  directory path "C:\Oracle\product\10.1.0\Client_1\jdbc\lib"

*/
lor: #333333;">=
conn.createStatement(); String query="select * from contacts"; ResultSet rs=stmt.executeQuery(query); System.out.println("Query Executed Successfully....."); while(rs.next()) { System.out.println("Name : "+rs.getString(1)); } }catch(Exception e) { System.out.println("Error : "+e); } } } /* Note : Download the required version of driver and place it into the below directory path "C:\Oracle\product\10.1.0\Client_1\jdbc\lib" */