Resolved Question
How can i connect oracle database from java program ? explain the steps with one example?
 
Details:
  asked by: mr_oizo  on: Apr 25, 2009  
 Best Answer ! ! !
beyond 's Answer  ( this answer is maked as best answer of this question at: May 5, 2009 )


DriverManager.registerDriver(new Oracle:jdbc:OracleDriver());Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "scott", "tiger");
1 comments  answered on: Apr 28, 2009 
Other Answer (7)

Class.forName( oracle.jdbc.driver.OracleDriver );
Connection con DriverManager.getConnection( dburl id password );
  alex_sin   answered on£ºApr 26, 2009  0 comments

Steps to follow in creation of JDBC program-



import java.sql.*;



public class driver1 {



public static void main() throws SQLException ClassNotFoundException {



Connection con null;



try {



class.forName( sun.jdbc.odbc.jdbcodbcDriver );



con DriverManager.getConnection( jdbc:odbc:datasourcename scott tiger );



Statement stmt con.CreateStatement();



Resultset rs stmt.executeQuery( Select * from EMP );



while(rs.next()) {



System.out.println(rs.getInt(1));



System.out.println(rs.getString(2));



}



int i stmt.executeUpdate( update EMP set sal sal 100 where eno '101' );



System.out.println(i rows updated );



con.close();



}



}
  hew   answered on£ºApr 27, 2009  0 comments

Class.forName ( oracld.jdbc.driver.OracleDriver );

Connection con DriverManager.getConnection ( jdbc:oracle:thin@localhose:1521:xe scott tiger );

xe is for oracle 10g

orcl is for oralce 8i and 9i

  pamelaesther   answered on£ºApr 28, 2009  0 comments

Hi friends Class.forName( oracle:jdbc:driver.OracleDriver );Connection c DriverManager.getConnection( jdbc:oracle:thin:@localhost:1521:myoracle scott tiger );scott-usernametiger-passwordmyoracle-SID nameSid name we are giving at the time of oracle install.In oracle 8i we can convert classes111.zip into classes111.jar and put at server lib in tomcat.In oracle 9i we can convert classes12.zip into classes12.jar and put at server lib in tomcat.
  hazeynut   answered on£ºApr 29, 2009  0 comments

import java.io.DataInputStream;import java.sql.DriverManager;import java.sql.Connection;import java.sql.Statement;import java.sql.SQLException;public class CRUDOperations{ public static void main(String raghu[])throws SQLException { Connection con null; try { DataInputStream dis new DataInputStream(System.in); Class.forName( oracle.jdbc.driver.OracleDriver ); con DriverManager.getConnection( dburl user pswd ); Statement st con.createStatement(); System.out.println( Enter the Employ id : ); int id Integer.parseInt(dis.readLine()); System.out.println( Enter the Employ Name : ); String name dis.readLine(); System.out.println( Enter the Employ salary : ); float salary Float.parseFloat(dis.readLine()); st.executeUpdate( insert values into Employee(id 'name' salary) ); } catch(Exception e) { e.printStackTrace(); } finally { con.close(); } }}
  dominiquekay   answered on£ºApr 30, 2009  0 comments

Close the Statement and the ResultSet as wel not only the Connection object.
  ahbinbin   answered on£ºMay 1, 2009  0 comments

Hello all

Following are the simple steps of jdbc



1) Load the Driver using the statement Class.forName( Oracle.jdbc.driver.OracleDriver );



2) Establish connection to the oracle database.

Connection conn DriverManager.getConnection( main prortocol:sub protocol:type4driver:name of oracle server:default port number(1521):service name username password );



Here

main protocol :Jdbc

Sub Protocol : Oracle

Type 4

Driver : thin

default port number is 1521

Service Name is Oracle9i

username is scott

password is Tiger



3) Design a query

example:

String query insert into table table name(? ? ?) ;



4)Create a statment Object Using prepared statement.

PreparedStatement pstat con.preparestatment(query);

here we need to pass the query

we are passing dynamic query using prepared statement.



5)Execute Query using pstat

pstat.executeQuery();



6) Close the connection



Regards

Ms.Supriya Ahire
  mrjustice   answered on£ºMay 2, 2009  0 comments

Hot Questions

Contact Us - IT-Interview