JDBC Notes
JDBC Notes
Java Application
JDBC API
https://visualstudio.microsoft.com/downloads/
https://www.javaguides.net/2019/07/login-application-using-
java-swing-jdbc-mysql-example-tutorial.html
https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-
usagenotes-connect-drivermanager.html
https://www.javaguides.net/2019/07/login-application-using-
java-swing-jdbc-mysql-example-tutorial.html
Prof. Anand Motwani, Faculty - SCSE,
VIT Bhopal University
1. Establish a connection
import java.sql.*;
Load the vendor specific driver
Class.forName("oracle.jdbc.driver.OracleDriver");
What do you think this statement does, and how?
Dynamically loads a driver class, for Oracle database
Make the connection
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@oracle-prod:1521:OPROD",
username, passwd);
What do you think this statement does?
Establishes connection to database by obtaining
a Connection object
Prof. Anand Motwani, Faculty - SCSE,
VIT Bhopal University
2. Create JDBC statement(s)
Statement stmt = con.createStatement() ;
Creates a Statement object for sending SQL statements
to the database
ResultSet rs = Stmt.executeQuery(queryLehigh);
//What does this statement do?
while (rs.next()) {
int ssn = rs.getInt("SSN");
String name = rs.getString("NAME");
int marks = rs.getInt("MARKS");
Prof. Anand Motwani, Faculty - SCSE,