package DB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class InsertEx
public static void main(String[] args) {
//step1 load the driver class
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection
con=DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe","system","1234");
System.out.println("data base connectected successfuly");
//step3 create the statement object
PreparedStatement stmt=con.prepareStatement("insert into emp values
(?,?,?)");
stmt.setInt(1,400);
stmt.setInt(2, 7);
stmt.setString(3, " London");
int i=stmt.executeUpdate();
System.out.println("record inserted "+i);
//step5 close the connection object
con.close();
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
System.out.println(e);
package DB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SelectTest
public static void main(String[] args) {
//step1 load the driver class
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection
con=DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe","system","1234");
System.out.println("data base connectected successfuly");
//step3 create the statement object
Statement stmt=con.createStatement();
//step4 execute query
ResultSet rs=stmt.executeQuery("select * from emp ");
while(rs.next())
System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
//step5 close the connection object
con.close();
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
System.out.println(e);
package DB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class UpdateEx
{
public static void main(String[] args) {
//step1 load the driver class
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection
con=DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe","system","1234");
System.out.println("data base connectected successfuly");
//step3 create the statement object
PreparedStatement stmt=con.prepareStatement("update emp set
empname=? where empId=?");
stmt.setString(1, "Talor");
stmt.setInt(2, 400);
int i=stmt.executeUpdate();
System.out.println("records updated"+i);
//step5 close the connection object
con.close();
} catch (ClassNotFoundException | SQLException e) {
// TODO Auto-generated catch block
System.out.println(e);