Содержание
- 2. Contents Introduction to JDBC Example Main classes & methods JDBC driver installation HW Assignment Directions for
- 3. JDBC Introduction to JDBC Example Main classes & method JDBC driver installation
- 4. Introduction to JDBC What is JDBC? “Java Database Connectivity” Connector to access DB, when developing applications
- 5. Example of JDBC code import java.sql.*; class Test { public static void main(String[] args) { Connection
- 6. Main classes & method Loading JDBC driver Using Class.forName() Connecting to DB Using DriverManager.getConnection() Class.forName(“oracle.jdbc.driver.OracleDriver”); Connection
- 7. Main classes & method (cont’d) Executing queries Using Statement class Using PreparedStatement class Statement stmt =
- 8. Main classes & method (cont’d) Cursor operations Use methods of ResultSet class Ex) next(), getString(), etc.
- 9. Main classes & method (cont’d) Using ‘finally’ Before finishing code, connection should be closed try {
- 10. Main classes & method (cont’d) Executing Query within a Transaction try { … con = DriverManager.getConnection(
- 11. JDBC driver installation JAVA SE 7.0 or 8.0 must be installed See references Download (ojdbc6.jar) http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
- 12. Compile java using DOS command Environment variable setting If you use the “Eclipse”, you don’t have
- 13. Compile java using DOS command (cont’d) Example of file execution in the DOS command(cmd) window Compiling
- 14. Compile java using Eclipse IDE Eclipse setting Add ojdbc6.jar to project build path Right click on
- 15. Compile java using Eclipse IDE (cont’d) Add External IDE ? select ojdbc6.jar
- 16. Homework #4 Table Creation Homework Assignment Directions References
- 17. Table creation Download HW4db.sql from the course homepage and copy it to (directory that Oracle Client
- 18. Homework #4 (cont’d) Problem 1 Ask the user for the maximum price and minimum values of
- 19. Problem 2. Ask the user for a manufacturer, model number, speed, RAM, hard-disk size, and price
- 20. Problem 3. Ask the user for a price and find the PC whose price is closest
- 21. Problem 4. Ask the user for a manufacturer. Print the specifications of all products by that
- 22. Problem 5. Ask the user for a “budget” (total price of a PC and printer), and
- 23. Submission Files to submit 1. JAVA (*.java) 2. Archive them into [student ID].zip and upload it
- 24. Submission (cont’d) Due date Oct 19 (Wed), 2 am. Delay is not accepted TA info. Hyun
- 26. Скачать презентацию