Guest User

Insert using JDBC

a guest
Jun 13th, 2018
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import java.sql.*;
  2. class insert{
  3. public static void main(String args[]){
  4. try{
  5. Class.forName("com.mysql.jdbc.Driver");
  6. Connection con=DriverManager.getConnection(
  7. "jdbc:mysql://localhost:3306/sonoo","root","root"); //put in your database ka name in place ofs sonoo
  8. PreparedStatement stmt=con.prepareStatement("insert into emp value(?,?)"); //put in your query in these parenthesis
  9. stmt.setInt(1,101);//1 specifies the first ? in the query
  10. stmt.setString(2,"Ratan"); //2 specifies the second question mark, similarly insert into all of your table ka fields...
  11. int i=stmt.executeUpdate();
  12. System.out.println(i+" records inserted");
  13. con.close();
  14. }catch(Exception e){ System.out.println(e);}
  15. }
  16. }
Add Comment
Please, Sign In to add comment