Karjala you downloaded the Oracle JDBC drivers, first download them, you can download the Oracle JDBC drivers here http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html Choose the version that suits your version Database.
Java program to connect to Oracle: The following Java program uses the Oracle JDBC driver to connect to an executable instance of an Oracle database. You can use this program in any Oracle database, as this example uses the built-in DUAL Dracy table to get the system date. DUAL allows you to retrieve values ββsuch as the system date using a regular SQL query.
1 // Java program example - connecting to an Oracle database 2 import java.sql.Connection; 3 import java.sql.Date; 4 import java.sql.DriverManager; 5 import java.sql.ResultSet; 6 import java.sql.SQLException; 7 import java.sql.Statement; eight
9 public class OracleSample {10
11 public static final String DBURL = "jdbc: oracle: thin: @localhost: 1521: XE"; 12 public static final String DBUSER = "system"; 13 public static final String DBPASS = "manager"; 14
15 public static void main (String [] args) throws SQLException {16
17 // Download the Oracle JDBC driver 18 DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver ()); 19
20 // Connection to the Oracle database 21 Connection con = DriverManager.getConnection (DBURL, DBUSER, DBPASS); 22
23 Statement statement = con.createStatement (); 24
25 // Executing a SELECT query in a DUAL DUAL Table. Useful for getting system values ββ26 // Allows us to get values ββas if the query from table 27 ResultSet rs = statement.executeQuery ("SELECT SYSDATE FROM DUAL"); 28
29th
30 if (rs.next ()) {31 Date currentDate = rs.getDate (1); // returns the first column 32 System.out.println ("Current date from Oracle:" + currentDate); 33} 34 rs.Close (); 35 statement.close (); 36 con.close (); 37} 38}
Hope this helps you guys ....... :-)
source share