Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.Statement;
  5.  
  6. import com.mysql.management.driverlaunched.ServerLauncherSocketFactory;
  7.  
  8. public class ConnectorMXJTestExample {
  9. public static void main(String[] args) throws Exception {
  10. String hostColonPort = "localhost:3336";
  11.  
  12. String driver = com.mysql.jdbc.Driver.class.getName();
  13. String url = "jdbc:mysql://" + hostColonPort + "/" + "?"
  14. + "socketFactory="
  15. + ServerLauncherSocketFactory.class.getName();
  16. String userName = "root";
  17. String password = "";
  18.  
  19. Class.forName(driver);
  20. Connection conn = null;
  21. try {
  22. conn = DriverManager.getConnection(url, userName, password);
  23. Statement stmt = conn.createStatement();
  24. ResultSet rs = stmt.executeQuery("SELECT VERSION()");
  25. rs.next();
  26. String version = rs.getString(1);
  27. rs.close();
  28. stmt.close();
  29.  
  30. System.out.println("------------------------");
  31. System.out.println(version);
  32. System.out.println("------------------------");
  33. } finally {
  34. try {
  35. conn.close();
  36. } catch (Exception e) {
  37. e.printStackTrace();
  38. }
  39. ServerLauncherSocketFactory.shutdown(hostColonPort);
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement