1. Add jar files
In Eclipse, after creating a new project -> right click on projname-> properties -> select Java Buildpath-> Add External Jars-> jar file path -> Ok
Jar file pathàC:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib
2. Start adding new class file
To use the DriverManager class to create connection objects, you need to know how to make a connection URL that provides access information to the Oracle server. The Oracle connection URL for the thin client-side driver ojdbc14.jar has the following format:
jdbc:oracle:thin:[user/password]@[host][:port]:SID
jdbc:oracle:thin:[user/password]@//[host][:port]/SID
user - The login user name defined in the Oracle server.
password - The password for the login user.
host - The host name where Oracle server is running.
Default is 127.0.0.1 - the IP address of localhost.
port - The port number where Oracle is listening for connection.
Default is 1521.
SID - System ID of the Oracle server database instance.
By default, Oracle Database 10g Express Edition creates one database instance called XE.
Ex: try {
Connection con=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:XE",
"system",
"password");
Statement s=con.createStatement();
s.execute("insert into emp values('attr1')");
s.close();
con.close();
} catch(Exception e){e.printStackTrace();}
No comments:
Post a Comment