0% found this document useful (0 votes)
26 views

Java - Database Connectivity

This document provides instructions for connecting to an Oracle database using JDBC in Java. It includes downloading Oracle 21c, creating a Java project in Eclipse, including the Oracle JDBC jar file in the build path, and provides sample code to connect to the database, insert records into a table, and handle exceptions.

Uploaded by

ragaven777
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)
26 views

Java - Database Connectivity

This document provides instructions for connecting to an Oracle database using JDBC in Java. It includes downloading Oracle 21c, creating a Java project in Eclipse, including the Oracle JDBC jar file in the build path, and provides sample code to connect to the database, insert records into a table, and handle exceptions.

Uploaded by

ragaven777
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
You are on page 1/ 3

JAVA DATABASE CONNECTIVITY

ORACLE:

Download ORACLE 21C

Open Ellipse

1. Create New Project and Select Java Project and Click ‘Finish’
2. Delete module-info,.java

3.Oracle jar File and Include in Build Path


Coding:
package ecomm;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class jdbc_conn {


public static void main(String[] args) throws IOException {
Connection conn1 = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn1 = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","admin","admin123!");
if (conn1 != null) {
System.out.println("Sucess ");
}
PreparedStatement psmt = conn1.prepareStatement("INSERT INTO EMP (ENAME) VALUES (?)");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int count =0;
while(true)
{
System.out.println("Enter the Name");
String ename1 = br.readLine();
psmt.setString(1, ename1);
count = count +1;
if (count <= 3)
{
System.out.println(count+ " Record Inserted ");
}
else
{
System.out.println("Total Racords Inserted "+count+"");
break;
}
count++;
}

}
catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
} finally

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy