Guest User

Untitled

a guest
Dec 4th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import com.mysql.jdbc.Statement;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. public class DatabaseConnection {
  9. public static void main(String[] args) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
  10. dbConnection();
  11. }
  12.  
  13. private static void dbConnection() throws ClassNotFoundException, SQLException, IllegalAccessException, InstantiationException {
  14.  
  15. Class.forName("com.mysql.jdbc.Driver");
  16. System.out.println("Driver loaded");
  17.  
  18. String url = "jdbc:mysql://localhost:3306/atomspace_db?autoReconnect=true&useSSL=false";
  19. String username = "root";
  20. String password = "************";
  21.  
  22. System.out.println("Connecting database...");
  23.  
  24. Connection connection = DriverManager.getConnection(url, username, password);
  25. Statement stmt = (Statement) connection.createStatement();
  26. stmt = (Statement) connection.createStatement();
  27. ResultSet rs = stmt.executeQuery("Select * from students");
  28. connection.close();
  29.  
  30. }
  31. }
Add Comment
Please, Sign In to add comment