Advertisement
Guest User

Untitled

a guest
Mar 16th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4.  
  5. public class TableReader {
  6.  
  7. static Connection getConnection() {
  8. Connection connection = null;
  9.  
  10. try {
  11. Class.forName("com.mysql.jdbc.Driver").newInstance();
  12. connection = DriverManager.getConnection(
  13. "jdbc:mysql://184.154.73.113/davidlno_StockHistory?" +
  14. "user=davidlno_student&password=ez24get!");
  15.  
  16. } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
  17. e.printStackTrace();
  18. } catch (SQLException e) {
  19. System.out.println("SQLException: " + e.getMessage());
  20. System.out.println("SQLState: " + e.getSQLState());
  21. System.out.println("VendorError: " + e.getErrorCode());
  22. }
  23.  
  24. return connection;
  25. }
  26.  
  27. public static void main(String[] args) {
  28. Connection connection = getConnection();
  29.  
  30. try {
  31. connection.close();
  32. } catch (SQLException e) {
  33. e.printStackTrace();
  34. }
  35. connection = null;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement