Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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