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(); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter