Prepared Insert
Fri Nov 15 2024 16:54:11 GMT+0000 (Coordinated Universal Time)
Saved by
@login123
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class InsertExample {
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "pragna");
String insertQuery = "INSERT INTO emp (EID, ESAL, ENAME) VALUES (?, ?, ?)";
PreparedStatement pstmt = con.prepareStatement(insertQuery);
pstmt.setInt(1, 30); // Set EID
pstmt.setInt(2, 50000); // Set ESAL
pstmt.setString(3, "Manish"); // Set ENAME
int rowsInserted = pstmt.executeUpdate();
System.out.println("Rows inserted: " + rowsInserted);
pstmt.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
content_copyCOPY
Comments