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