import java.sql.*; public class Insertprepared{ public static void main(String args[]) { Connection con = null; PreparedStatement pst = null; ResultSet rs = null; String url = "jdbc:mysql://192.168.10.13:3306/"; String db = "ankdb"; String driver = "com.mysql.jdbc.Driver"; String user = "root"; String pass = "root"; try { Class.forName(driver); con = DriverManager.getConnection(url + db, user, pass); con.setAutoCommit(false);// Disables auto-commit. String sql = "insert into student values(?,?,?) "; pst = con.prepareStatement(sql); pst.setInt(1,1642); pst.setString(2, "Rahul"); pst.setString(3,"1985-06-06"); pst.executeUpdate(); sql = "select * from student"; rs = pst.executeQuery(sql); System.out.println("Roll No \tName \t\tDate of Birth"); while (rs.next()) { System.out.print(rs.getInt(1) + " \t"); System.out.print(rs.getString(2) + " \t"); System.out.print(rs.getDate(3) + " \t"); System.out.println(""); } rs.close(); pst.close(); con.close(); } catch (Exception e) { System.out.println(e); } } }