Jdbc connectivity program
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
public class OracleJDBCExample {
public static void main(String[] args) {
try {
// 1. Load Oracle Driver
[Link]("[Link]");
// 2. Create Connection
Connection con = [Link](
"jdbc:oracle:thin:@localhost:1521:xe",
"system",
"system"
);
[Link]("Connected to Oracle Database Successfully!");
// 3. Create Statement
Statement stmt = [Link]();
// 4. Execute SELECT Query
ResultSet rs = [Link]("SELECT * FROM student_msc");
// 5. Process ResultSet
while([Link]()) {
int no = [Link](1);
String name = [Link](2);
[Link]("ID: " + no + " Name: " + name);
// 3. Get User Input
Scanner sc = new Scanner([Link]);
[Link]("Enter Student ID: ");
int id = [Link]();
[Link]("Enter Student Name: ");
String name = [Link]();
// 4. Prepare SQL Query
String sql = "INSERT INTO student_msc VALUES (?, ?)";
PreparedStatement ps = [Link](sql);
// 5. Set Values
[Link](1, id);
[Link](2, name);
// 6. Execute Update
int rows = [Link]();
if(rows > 0)
[Link]("Record Inserted Successfully!");
else
[Link]("Insertion Failed!");
// 5. Close Connection
[Link]();
catch (Exception e) {
[Link](e);
Output: