Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4. import java.sql.Statement;
  5. /*
  6. * @author nitish
  7. */
  8. public class Database {
  9. public static void main(String[] args) {
  10.  
  11. try{
  12. Class.forName("com.mysql.jdbc.Driver");
  13. Connection con=DriverManager.getConnection(
  14. "jdbc:mysql://localhost:3306/dbname","root","");
  15. Statement stmt=con.createStatement();
  16. String sql = "INSERT INTO tablename " +"VALUES ('Java Programmer');";
  17. stmt.executeUpdate(sql);
  18. con.close();
  19. }catch( ClassNotFoundException | SQLException e){
  20. System.out.println(e);
  21. }
  22.  
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement