For Oracle :-
1. from following location copy the ojdbc6.jar file
C:\app\RAUSHAN\product\11.1.0\db_1\jdbc\lib :- Where RAUSHAN is my username
and paste this jar file into following location
C:\Program Files\Java\jre7\lib\ext
2. now use these codes into ur program
---> Class.forName("oracle.jdbc.driver.OracleDriver"); //to load the driver
---> Connection con =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL","raushan","raushan");
//To establish the connection
1. Here jdbc is the API
2. oracle is database
3. thin is driver
4. localhost is the server name on which oracle is running
5. 1521 is the port number
6. ORCL is the oracle service name, it is by default in 11g,
if its not working then u can find ur oracle service name
by executing following command...
sql > define
it will give u a list, on that list u can check the
DEFINE_CONNECT_IDENTIFIER, it will give ur oracle service name
7. "raushan" is the username in oracle
8. and 2nd "raushan" is the password for "raushan" user
----> Statement s=con.createStatement();
s.executeUpdate("insert/update/delete query");
s.execute("create query statement");
s.executeQuery("select query statement");
----> ResultSet rs=s.getResultSet(); //to store the return value of queries
rs.next() - it will initially point to the first tuple and after each call of this method it will jump to next tuple
rs.getString(<column no>) - it will return the value of column by providing the column no.
-----> s.close() // to close the statement
con.close()//to disconnect the connection
Thanks for visiting my blog. My next blog will be on "connectivity with java and mysql".
No comments:
Post a Comment