0% found this document useful (0 votes)
2 views4 pages

JDBC Connectivity Program

The document is a Java program that demonstrates JDBC connectivity to an Oracle database. It connects to the database, retrieves and displays records from a 'student_msc' table, and allows the user to insert new records based on input. The program handles exceptions and ensures the database connection is closed after operations.

Uploaded by

msccslab25
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

JDBC Connectivity Program

The document is a Java program that demonstrates JDBC connectivity to an Oracle database. It connects to the database, retrieves and displays records from a 'student_msc' table, and allows the user to insert new records based on input. The program handles exceptions and ensures the database connection is closed after operations.

Uploaded by

msccslab25
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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:

You might also like