Advertisement
Guest User

Untitled

a guest
Jan 14th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. package sql;
  2.  
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5.  
  6. import com.mysql.jdbc.Statement;
  7.  
  8. public class Main {
  9.  
  10. public static void main(String[] args) throws ClassNotFoundException, SQLException {
  11.  
  12. Class.forName("com.mysql.jdbc.Driver");
  13.  
  14. java.sql.Connection conn1 = null;
  15.  
  16.  
  17. try {
  18. // connect way #1
  19. String url1 = "jdbc:mysql://sql2.freemysqlhosting.net:3306/sql2215281";
  20. String user = "sql2215281";
  21. String password = "dZ8%xB2!";
  22.  
  23. conn1 = DriverManager.getConnection(url1, user, password);
  24. if (conn1 != null) {
  25. System.out.println("Connected to the database");
  26. }
  27.  
  28. } catch (SQLException ex) {
  29. // handle any errors
  30. System.out.println("SQLException: " + ex.getMessage());
  31. System.out.println("SQLState: " + ex.getSQLState());
  32. System.out.println("VendorError: " + ex.getErrorCode());
  33.  
  34. }
  35.  
  36. java.sql.Statement statement = conn1.createStatement();
  37.  
  38. statement.execute("sql statement here")
  39.  
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement