Advertisement
Guest User

Untitled

a guest
Nov 28th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6. import java.util.logging.Level;
  7. import java.util.logging.Logger;
  8.  
  9. public class Version {
  10.  
  11. public static void main(String[] args) {
  12.  
  13. Connection con = null;
  14. Statement st = null;
  15. ResultSet rs = null;
  16.  
  17. String url = "jdbc:mysql://localhost:3306/world_x?autoReconnect=true&useSSL=false";
  18. String user = "root";
  19. String password = "kj";
  20.  
  21. try {
  22.  
  23. con = DriverManager.getConnection(url, user, password);
  24. st = con.createStatement();
  25. rs = st.executeQuery("SELECT VERSION()");
  26.  
  27. if (rs.next()) {
  28.  
  29. System.out.println(rs.getString(1));
  30. }
  31.  
  32. } catch (SQLException ex) {
  33.  
  34. Logger lgr = Logger.getLogger(Version.class.getName());
  35. lgr.log(Level.SEVERE, ex.getMessage(), ex);
  36.  
  37. } finally {
  38.  
  39. try {
  40.  
  41. if (rs != null) {
  42. rs.close();
  43. }
  44.  
  45. if (st != null) {
  46. st.close();
  47. }
  48.  
  49. if (con != null) {
  50. con.close();
  51. }
  52.  
  53. } catch (SQLException ex) {
  54.  
  55. Logger lgr = Logger.getLogger(Version.class.getName());
  56. lgr.log(Level.WARNING, ex.getMessage(), ex);
  57. }
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement