Download presentation
Presentation is loading. Please wait.
Published byEthel Parker Modified over 9 years ago
1
What software components are required? How do I install the Oracle JDBC driver? How do I connect to the database? What form is the data in and how do I use it? How can I manipulate the database in code? Why is it important to clean up connection resources?
2
Oracle 10g Express -- Installed correctly -- Configured correctly (default/named instance, Schemes…) Oracle JDBC driver (ojdbc14.jar) Java SDK 1.4 or later Oracle 10g Express ojdbc14.jar Java App (Connection )
3
Include the ojdbc14.jar path in the Java CLASSPATH or add to your IDE’s compile- time libraries set (NetBeans, Eclipse..) Load the JDBC driver into the JRE using the Class.forName(“oracle.jdbc.OracleDriver”) method (see code for complete details)
4
Carefully construct your connection string Format: “jdbc:oracle:thin:[user/pwd]@host:port:server” My Instance: “jdbc:oracle:thin:system/noeyedpirate@localhost:1521:XE”
5
Establish the connection using DriverManager.getConnection(connString) This returns a java.sql.Connection Object -- With this instance of Connection you can: --Execute queries (returns data) --Execute updates (no data returned)
6
An instance of the java.sql.ResultSet Class is what is returned when a java.sql.Statement Object executes a query. Returns a table data structure Statement.exec uteQuery(sql) ResultSet Connection.crea teStatement DriverManager. getConnection Java App Process data
7
Query: string sql = “SELECT * FROM Suppliers”; stmt = dbConn.createStatement(“params”); ResultSet result = stmt.executeQuery(sql); (see code for complete details) Update: string sql = “DROP TABLE Suppliers”; stmt = dbConn.createStatement(“params”); int tempInt = stmt.executeUpdate(sql);
8
It is very important to clean up your Connection, Statement, and ResultSet Objects after use! If you have a ResultSet open during the same time that you try to open a new one in the same memory space you will get a run-time error!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.