Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DatabaseMetaData;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5.  
  6. public class MetaDataBasicInfo {
  7.  
  8. public static void main(String[] args) throws SQLException {
  9.  
  10. Connection myConn = null;
  11.  
  12. try {
  13. // 1. Get a connection to database
  14. myConn = DriverManager.getConnection(
  15. "jdbc:mysql://localhost:3306/demo", "student", "student");
  16.  
  17. // 2. Get metadata
  18. DatabaseMetaData databaseMetaData = myConn.getMetaData();
  19.  
  20. // 3. Display info about database
  21. System.out.println("Product name: " + databaseMetaData.getDatabaseProductName());
  22. System.out.println("Product version: " + databaseMetaData.getDatabaseProductVersion());
  23. System.out.println();
  24.  
  25. // 4. Display info about JDBC Driver
  26. System.out.println("JDBC Driver name: " + databaseMetaData.getDriverName());
  27. System.out.println("JDBC Driver version: " + databaseMetaData.getDriverVersion());
  28.  
  29. } catch (Exception exc) {
  30. exc.printStackTrace();
  31. } finally {
  32. close(myConn);
  33. }
  34. }
  35.  
  36. private static void close(Connection myConn)
  37. throws SQLException {
  38.  
  39. if (myConn != null) {
  40. myConn.close();
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement