Advertisement
Guest User

MySQL-Tester

a guest
Feb 17th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. /*
  2. * Web: http://www.cyberdos.de
  3. * Mail: info@cyberdos.de
  4. */
  5. package mysqltester;
  6.  
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.SQLException;
  10.  
  11. /**
  12. *
  13. * @author tim.koch@cyberdos.de
  14. */
  15. public class MysqlTester {
  16.  
  17. public static final String MainDB_Hostname = "jdbc:mysql://10.100.3.5/sql13";
  18. public static final String MainDB_Username = "sql13";
  19. public static final String MainDB_Password = "9JMYXzrus1";
  20.  
  21. /**
  22. * @param args the command line arguments
  23. */
  24. public static void main(String[] args) {
  25. loadDrivers();
  26.  
  27. Connection admin_conn = Connect(MainDB_Hostname, MainDB_Username, MainDB_Password);
  28. if(admin_conn == null) {
  29. System.out.println("Verbindung zur Datenbank *Main_DB* konnte nicht hergestellt werden!");
  30. } else {
  31. System.out.println("Verbindung zur Datenbank *Main_DB* wurde hergestellt!");
  32. }
  33. }
  34.  
  35. private static void loadDrivers() {
  36. try {
  37. System.out.println("* SQL Treiber laden");
  38. Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  39. System.out.println(Class.forName("org.gjt.mm.mysql.Driver").toString());
  40. System.out.println(Class.forName("org.gjt.mm.mysql.Driver").newInstance().toString());
  41. }
  42. catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
  43. System.err.println("Unable to load driver.");
  44. }
  45. }
  46.  
  47. /**
  48. * @param hostname Hostname of MySQL-Server.
  49. * @param user Username to login to the MysSQL-Server.
  50. * @param password Password to login to the MysSQL-Server.
  51. */
  52. private static Connection Connect(String hostname, String user, String password) {
  53. Connection conn = null;
  54.  
  55. try {
  56. conn = DriverManager.getConnection(hostname, user, password);
  57. return conn;
  58. }
  59. catch (SQLException sqle) {
  60. System.out.println("SQLException: " + sqle.getMessage());
  61. System.out.println("SQLState: " + sqle.getSQLState());
  62. System.out.println("VendorError: " + sqle.getErrorCode());
  63. }
  64. return null;
  65. }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement