Development of Salary Grades using JDBC
Transcript of Development of Salary Grades using JDBC
![Page 1: Development of Salary Grades using JDBC](https://reader031.fdocuments.in/reader031/viewer/2022040911/624e55bfabd67449b11e2367/html5/thumbnails/1.jpg)
Development of Salary Grades using JDBC
By: Dixie Bartholomew
![Page 2: Development of Salary Grades using JDBC](https://reader031.fdocuments.in/reader031/viewer/2022040911/624e55bfabd67449b11e2367/html5/thumbnails/2.jpg)
What is my project?
• I wrote a Java program which takes an employee’s Id from the user and return the name, job title, salary, and salary grade.
• The program uses JDBC to connect to the Database.
![Page 3: Development of Salary Grades using JDBC](https://reader031.fdocuments.in/reader031/viewer/2022040911/624e55bfabd67449b11e2367/html5/thumbnails/3.jpg)
What is JDBC?
• JDBC(Java Database Connectivity) is a Java API for executing SQL statements.
• Using JDBC, it is easy to send SQL statements to almost any relational database.
![Page 4: Development of Salary Grades using JDBC](https://reader031.fdocuments.in/reader031/viewer/2022040911/624e55bfabd67449b11e2367/html5/thumbnails/4.jpg)
Four JDBC Driver Categories
• JDBC-ODBC bridge plus ODBC driver
• Native-API partly Java Driver
• JDBC-Net pure Java Driver
• Native-protocol pure Java driver
![Page 5: Development of Salary Grades using JDBC](https://reader031.fdocuments.in/reader031/viewer/2022040911/624e55bfabd67449b11e2367/html5/thumbnails/5.jpg)
ODBC Data Source Administrator
• Select the appropriate driver.
• Enter the data source name inside the setup window.
• Select the directory where the database’s files are stored.
![Page 6: Development of Salary Grades using JDBC](https://reader031.fdocuments.in/reader031/viewer/2022040911/624e55bfabd67449b11e2367/html5/thumbnails/6.jpg)
Three steps involved in JDBC
• Establish the connection with the database.
• Send SQL statements.
• Process the Results.
![Page 7: Development of Salary Grades using JDBC](https://reader031.fdocuments.in/reader031/viewer/2022040911/624e55bfabd67449b11e2367/html5/thumbnails/7.jpg)
Establishing the Connection
• The following is code used to connect to the database
• Connection con = DriverManager.getConnection
( “jdbc:odbc:abra”, “login”, “password”);
![Page 8: Development of Salary Grades using JDBC](https://reader031.fdocuments.in/reader031/viewer/2022040911/624e55bfabd67449b11e2367/html5/thumbnails/8.jpg)
The three parts to the URL
• Protocol
• subprotocol
• subname
![Page 9: Development of Salary Grades using JDBC](https://reader031.fdocuments.in/reader031/viewer/2022040911/624e55bfabd67449b11e2367/html5/thumbnails/9.jpg)
Sending SQL Statements
• The SQL Statements are:
• Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery( “SELECT P_EMPNO, P_FNAME, P_LNAME, P_JOBTITLE, P_ANNUAL FROM hrPersnl.dbf”);
• P_EMPNO P_FNAME P_LNAME 816001 Sally Parker 816002 Billy Smith 816003 Tina Jones
![Page 10: Development of Salary Grades using JDBC](https://reader031.fdocuments.in/reader031/viewer/2022040911/624e55bfabd67449b11e2367/html5/thumbnails/10.jpg)
Processing the Results
• I = 0; while ( rs.next ()) {
Id[I] = rs.getInt (“P_EMPNO”); fname[I] = rs.getString(“P_FNAME”); lname[I] = rs.getString(“P_LNAME”); jobtitle[I] = rs.getString(P_JOBTITLE”); salary[I] = rs.getFloat(“P_ANNUAL”); I+
+; }
![Page 11: Development of Salary Grades using JDBC](https://reader031.fdocuments.in/reader031/viewer/2022040911/624e55bfabd67449b11e2367/html5/thumbnails/11.jpg)
When will this be useful?
• Promotions • New Hire Purposes • Up Grading Positions • Scheduled Performance Reviews.
![Page 12: Development of Salary Grades using JDBC](https://reader031.fdocuments.in/reader031/viewer/2022040911/624e55bfabd67449b11e2367/html5/thumbnails/12.jpg)
Problems
• Registering the Database in the ODBC Data Source Administrator.
• JDBC Code
• Syntax