Connection con = DriverManager.getConnection ("jdbc:oracle:thin@localhose:1521:xe","scott","tiger");
xe is for oracle 10g
orcl is for oralce 8i and 9i
Jayakanthan
Oct 26th, 2006
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.
Raghuram Edadala
Nov 24th, 2006
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(); } }}
Close the Statement and the ResultSet as wel, not only the Connection object.
Supriya Ahire
Feb 2nd, 2007
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.
Step 2: Register the driver with the following command:- Class.For.Name("sun.jdbc.odbc.JdbcOdbcDriver");
Step 3:- Create the connection with database:- Connection cn = DriverManage.getConnection("Jdbc:Odbc:name of dsn");
Step 4:- Open the connection:- cn.open();
Step 5:- For Insertion of data:- PreparedStatement ps = cn.prepareStatement("insert into <table name> values(?,?,?,?)"); ps.setInt(1,Integer.parseInt(t1.setText())); ps.setString(2,t2.setText());
Step 6:- Execute the command:- ps.executeUpdate();
Step 7:- Close the connection:- cn.close();
NOTE:- Above step 7 is for only insertion of data.
"for retreival of data do same till step no 4 and then type the following command":- ResultSet rs;
Rules of making DSN:- Go to Control Panel -> Administrative Tools -> ODBC -> Add ->SQL Server -> Finish -> Name(any type) -> Next -> Next -> Folder name ->Next -> Finish -> Test -> Ok -> Finish.
How can i connect oracle database from java program ? explain the steps with one example?
Questions by vengal79
Related Answered Questions
Related Open Questions