List of usage examples for java.sql DatabaseMetaData getDatabaseProductVersion
String getDatabaseProductVersion() throws SQLException;
From source file:net.risesoft.soa.asf.web.controller.SystemController.java
private List<SysInfo> getDBInfo() { List list = new ArrayList(); String group = "4. ??"; try {//from w w w.jav a 2 s . c om Connection conn = this.basicDataSource.getConnection(); try { DatabaseMetaData dbmd = conn.getMetaData(); list.add(new SysInfo("DatabaseProductName", dbmd.getDatabaseProductName(), group)); list.add(new SysInfo("DatabaseProductVersion", dbmd.getDatabaseProductVersion(), group)); list.add(new SysInfo("DatabaseMajorVersion", Integer.valueOf(dbmd.getDatabaseMajorVersion()), group)); list.add(new SysInfo("DatabaseMinorVersion", Integer.valueOf(dbmd.getDatabaseMinorVersion()), group)); list.add(new SysInfo("DriverName", dbmd.getDriverName(), group)); list.add(new SysInfo("DriverVersion", dbmd.getDriverVersion(), group)); list.add(new SysInfo("DriverMajorVersion", Integer.valueOf(dbmd.getDriverMajorVersion()), group)); list.add(new SysInfo("DriverMinorVersion", Integer.valueOf(dbmd.getDriverMinorVersion()), group)); } finally { conn.close(); } group = "5. ?"; BasicDataSource bds = this.basicDataSource; list.add(new SysInfo("InitialSize", Integer.valueOf(bds.getInitialSize()), group)); list.add(new SysInfo("MaxActive", Integer.valueOf(bds.getMaxActive()), group)); list.add(new SysInfo("MaxIdle", Integer.valueOf(bds.getMaxIdle()), group)); list.add(new SysInfo("MinIdle", Integer.valueOf(bds.getMinIdle()), group)); list.add(new SysInfo("MaxWait", Long.valueOf(bds.getMaxWait()), group)); list.add(new SysInfo("NumActive", Integer.valueOf(bds.getNumActive()), group)); list.add(new SysInfo("NumIdle", Integer.valueOf(bds.getNumIdle()), group)); list.add(new SysInfo("DriverClass", bds.getDriverClassName(), group)); list.add(new SysInfo("URL", bds.getUrl(), group)); list.add(new SysInfo("Username", bds.getUsername(), group)); list.add(new SysInfo("Password", "******", group)); } catch (Exception ex) { log.warn("???: " + ex.getMessage(), ex); } return list; }
From source file:org.openmrs.module.databasebackup.util.DbDump.java
/** Dump the whole database to an SQL string */ public static void dumpDB(Properties props, boolean showProgress, Class showProgressToClass) throws Exception { String filename = props.getProperty("filename"); String folder = props.getProperty("folder"); String driverClassName = props.getProperty("driver.class"); String driverURL = props.getProperty("driver.url"); DatabaseMetaData dbMetaData = null; Connection dbConn = null;/*from ww w .j ava 2 s. c o m*/ Class.forName(driverClassName); dbConn = DriverManager.getConnection(driverURL, props); dbMetaData = dbConn.getMetaData(); FileOutputStream fos = new FileOutputStream(folder + filename); OutputStreamWriter result = new OutputStreamWriter(fos, fileEncoding); String catalog = props.getProperty("catalog"); String schema = props.getProperty("schemaPattern"); String tablesIncluded = props.getProperty("tables.included"); List<String> tablesIncludedVector = Arrays.asList(tablesIncluded.split(",")); String tablesExcluded = props.getProperty("tables.excluded"); List<String> tablesExcludedVector = Arrays.asList(tablesExcluded.split(",")); ResultSet rs = dbMetaData.getTables(catalog, schema, null, null); int progressCnt = 0; log.debug("tablesIncluded: " + tablesIncluded); log.debug("tablesExcluded: " + tablesExcluded); result.write("/*\n" + " * DB jdbc url: " + driverURL + "\n" + " * Database product & version: " + dbMetaData.getDatabaseProductName() + " " + dbMetaData.getDatabaseProductVersion() + "\n" + " */"); result.write("\nSET FOREIGN_KEY_CHECKS=0;\n"); List<String> tableVector = new Vector<String>(); int progressTotal = 0; while (rs.next()) { String tableName = rs.getString("TABLE_NAME"); if ((tablesIncluded.contains("all") && !tablesExcludedVector.contains(tableName) || tablesIncluded.contains(tableName)) || (tablesExcludedVector.contains("none") && !tablesIncludedVector.contains("none"))) { progressTotal++; tableVector.add(tableName); } } rs.beforeFirst(); if (!rs.next()) { log.error("Unable to find any tables matching: catalog=" + catalog + " schema=" + schema + " tables=" + tableVector.toArray().toString()); rs.close(); } else { do { String tableName = rs.getString("TABLE_NAME"); String tableType = rs.getString("TABLE_TYPE"); if (tableVector.contains(tableName)) { progressCnt++; //BackupFormController.getProgressInfo().put(filename, "Backing up table " + progressCnt + " of " + progressTotal + " (" + tableName + ")..."); if (showProgress) { Map<String, String> info = (Map<String, String>) showProgressToClass .getMethod("getProgressInfo", null).invoke(showProgressToClass); info.put(filename, "Backing up table " + progressCnt + " of " + progressTotal + " (" + tableName + ")..."); showProgressToClass.getMethod("setProgressInfo", new Class[] { Map.class }) .invoke(showProgressToClass, info); } if ("TABLE".equalsIgnoreCase(tableType)) { result.write("\n\n-- Structure for table `" + tableName + "`\n"); result.write("DROP TABLE IF EXISTS `" + tableName + "`;\n"); PreparedStatement tableStmt = dbConn .prepareStatement("SHOW CREATE TABLE " + tableName + ";"); ResultSet tablesRs = tableStmt.executeQuery(); while (tablesRs.next()) { result.write(tablesRs.getString("Create Table") + ";\n\n"); } tablesRs.close(); tableStmt.close(); dumpTable(dbConn, result, tableName); System.gc(); } } } while (rs.next()); rs.close(); } result.write("\nSET FOREIGN_KEY_CHECKS=1;\n"); result.flush(); result.close(); dbConn.close(); }
From source file:org.opoo.oqs.core.AbstractQueryFactory.java
public void afterPropertiesSet() { String databaseName = null;//from w w w . j a v a 2s .c om int databaseMajorVersion = 0; Connection conn = null; try { conn = connectionManager.getConnection(); DatabaseMetaData meta = conn.getMetaData(); databaseName = meta.getDatabaseProductName(); databaseMajorVersion = getDatabaseMajorVersion(meta); log.info("RDBMS: " + databaseName + ", version: " + meta.getDatabaseProductVersion()); log.info("JDBC driver: " + meta.getDriverName() + ", version: " + meta.getDriverVersion()); } catch (SQLException sqle) { log.warn("Could not obtain connection metadata", sqle); } catch (UnsupportedOperationException uoe) { // user supplied JDBC connections } finally { connectionManager.releaseConnection(conn); } if (dialect == null) { dialect = this.determineDialect(databaseName, databaseMajorVersion); } }
From source file:com.googlecode.psiprobe.controllers.sql.ConnectionTestController.java
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String resourceName = ServletRequestUtils.getStringParameter(request, "resource"); DataSource dataSource = null; try {/*from w ww .ja va 2s .co m*/ dataSource = getContainerWrapper().getResourceResolver().lookupDataSource(context, resourceName, getContainerWrapper()); } catch (NamingException e) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } if (dataSource == null) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } else { try { // TODO: use Spring's jdbc template? Connection conn = dataSource.getConnection(); try { DatabaseMetaData md = conn.getMetaData(); List dbMetaData = new ArrayList(); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdName", md.getDatabaseProductName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdVersion", md.getDatabaseProductVersion()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverName", md.getDriverName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverVersion", md.getDriverVersion()); // addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcVersion", String.valueOf(md.getJDBCMajorVersion())); return new ModelAndView(getViewName(), "dbMetaData", dbMetaData); } finally { conn.close(); } } catch (SQLException e) { String message = getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.connection.failure", new Object[] { e.getMessage() }); logger.error(message, e); request.setAttribute("errorMessage", message); } } return new ModelAndView(getViewName()); }
From source file:za.co.eon.econtentsolutions.component.abstractlticomponent.AbstractLTIComponentServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//ww w.j a v a 2 s.co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try (PrintWriter out = response.getWriter()) { Launch launch = tsugi.getLaunch(request, response); if (launch.isComplete()) { launch.getOutput().flashSuccess("LTI Launch validated and redirected"); log.info("LTI Launch validated and redirected..."); return; } if (!launch.isValid()) { out.println("<pre>"); out.println("Launch is not valid but nowhere to redirect"); out.println(launch.getErrorMessage()); out.println("Base String:"); out.println(launch.getBaseString()); out.println("</pre>"); out.close(); throw new RuntimeException(launch.getErrorMessage()); } HttpSession session = request.getSession(); Output o = launch.getOutput(); Properties versions = o.header(out); o.bodyStart(out); o.flashMessages(out); // out.println("<pre>"); // Dump out some stuff from the Request Object out.println(""); out.println( "<a href=\"http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html\" target=\"_blank\">HttpServletRequest</a> data:"); out.println("req.getRequestURL()=" + request.getRequestURL()); out.println("req.getMethod()=" + request.getMethod()); out.println("req.getServletPath()=" + request.getServletPath()); out.println("req.getPathInfo()=" + request.getPathInfo()); out.println("req.getQueryString()=" + request.getQueryString()); out.println(""); out.print("<a href=\""); out.print(launch.getGetUrl(null) + "/zap"); out.println("\">Click here to see if we stay logged in with a GET</a>"); out.println(""); out.println( "Using the <a href=\"http://csev.github.io/tsugi-java/apidocs/index.html\" target=\"_blank\">Tsugi API</a>:"); out.println("Content Title: " + launch.getContext().getTitle()); out.println("Context Settings: " + launch.getContext().getSettings().getSettingsJson()); out.println("User Email: " + launch.getUser().getEmail()); out.println("isInstructor()=" + launch.getUser().isInstructor()); out.println("isTenantAdmin()=" + launch.getUser().isTenantAdmin()); out.println("Link Title: " + launch.getLink().getTitle()); out.println("Link Settings: " + launch.getLink().getSettings().getSettingsJson()); out.println("Sourcedid: " + launch.getResult().getSourceDID()); out.println("Service URL: " + launch.getService().getURL()); out.println(""); out.println("JavaScript library versions:"); out.println(TsugiUtils.dumpProperties(versions)); out.println(""); out.println("Using the provided JDBC connection:"); Connection c = null; try { c = launch.getConnection(); out.println("Connection: " + c); DatabaseMetaData meta = c.getMetaData(); String productName = meta.getDatabaseProductName(); String productVersion = meta.getDatabaseProductVersion(); String URL = meta.getURL(); out.println("Connection product=" + productName + " version=" + productVersion); out.println("Connection URL=" + URL); } catch (Exception ex) { log.error("Unable to get connection metadata", ex); out.println("Unable to get connection metadata:" + ex.getMessage()); } // Do a simple query just to see how it is done if (c != null) { Statement stmt = null; String query = "SELECT plugin_id, plugin_path FROM lms_plugins;"; try { stmt = c.createStatement(); ResultSet rs = stmt.executeQuery(query); int num = 0; while (rs.next()) { String plugin_path = rs.getString("plugin_path"); out.println("plugin_path=" + plugin_path); num++; } out.println("Successfully read " + num + " rows from the database"); } catch (SQLException e) { out.println("Problems reading database"); out.println("INSERT INTO mjjs (name) VALUES ('tsugi');"); e.printStackTrace(); } } // Cheat and look at the internal data Tsugi maintains - this depends on // the JDBC implementation Properties sess_row = (Properties) session.getAttribute("lti_row"); if (sess_row != null) { out.println(""); out.println("Tsugi-managed internal session data (Warning: org.tsugi.impl.jdbc.Tsugi_JDBC only)"); String x = TsugiUtils.dumpProperties(sess_row); out.println(x); } out.println("</pre>"); // Do the Footer o.footerStart(out); out.println("<!-- App footer stuff goes here -->"); o.footerEnd(out); out.close(); } catch (RuntimeException re) { try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>AbstractLTIComponentServlet Error</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>AbstractLTIComponentServlet</h1>"); out.println("<h3 style=\"color: red;\">Error</h3>"); out.println("<p>Servlet AbstractLTIComponentServlet at " + request.getContextPath() + " threw an exception.</p>"); out.println("<p>Exception: " + re.toString() + "<br />"); out.println("Message: " + re.getMessage() + "<br />"); out.println("Stacktrace:</p>"); out.println("<p>" + re.getStackTrace().toString() + "</p>"); out.println("</body>"); out.println("</html>"); } } }
From source file:net.testdriven.psiprobe.controllers.sql.ConnectionTestController.java
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String resourceName = ServletRequestUtils.getStringParameter(request, "resource"); DataSource dataSource = null; try {//from ww w.j a v a 2 s . co m dataSource = getContainerWrapper().getResourceResolver().lookupDataSource(context, resourceName); } catch (NamingException e) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } if (dataSource == null) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } else { try { // TODO: use Spring's jdbc template? try (Connection conn = dataSource.getConnection()) { DatabaseMetaData md = conn.getMetaData(); List<Map<String, String>> dbMetaData = new ArrayList<>(); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdName", md.getDatabaseProductName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdVersion", md.getDatabaseProductVersion()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverName", md.getDriverName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverVersion", md.getDriverVersion()); // addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcVersion", String.valueOf(md.getJDBCMajorVersion())); return new ModelAndView(getViewName(), "dbMetaData", dbMetaData); } } catch (SQLException e) { String message = getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.connection.failure", new Object[] { e.getMessage() }); logger.error(message, e); request.setAttribute("errorMessage", message); } } return new ModelAndView(getViewName()); }
From source file:com.alibaba.dubbo.governance.status.DatabaseStatusChecker.java
public Status check() { boolean ok;//from w ww . j a v a2 s. c o m try { Connection connection = dataSource.getConnection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet resultSet = metaData.getTypeInfo(); try { ok = resultSet.next(); } finally { resultSet.close(); } if (message == null) { message = metaData.getURL() + " (" + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion() + ", " + getIsolation(metaData.getDefaultTransactionIsolation()) + ")"; } if (version == 0) { version = metaData.getDatabaseMajorVersion(); } } finally { connection.close(); } } catch (Throwable e) { logger.error(e.getMessage(), e); ok = false; } return new Status(!ok ? Status.Level.ERROR : (version < 5 ? Status.Level.WARN : Status.Level.OK), message); }
From source file:psiprobe.controllers.sql.ConnectionTestController.java
@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String resourceName = ServletRequestUtils.getStringParameter(request, "resource"); DataSource dataSource = null; try {//ww w. j a v a 2 s.c om dataSource = getContainerWrapper().getResourceResolver().lookupDataSource(context, resourceName, getContainerWrapper()); } catch (NamingException e) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); logger.trace("", e); } if (dataSource == null) { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.resource.lookup.failure", new Object[] { resourceName })); } else { try { // TODO: use Spring's jdbc template? try (Connection conn = dataSource.getConnection()) { DatabaseMetaData md = conn.getMetaData(); List<Map<String, String>> dbMetaData = new ArrayList<>(); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdName", md.getDatabaseProductName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.dbProdVersion", md.getDatabaseProductVersion()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverName", md.getDriverName()); addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcDriverVersion", md.getDriverVersion()); // addDbMetaDataEntry(dbMetaData, "probe.jsp.dataSourceTest.dbMetaData.jdbcVersion", // String.valueOf(md.getJDBCMajorVersion())); return new ModelAndView(getViewName(), "dbMetaData", dbMetaData); } } catch (SQLException e) { String message = getMessageSourceAccessor() .getMessage("probe.src.dataSourceTest.connection.failure", new Object[] { e.getMessage() }); logger.error(message, e); request.setAttribute("errorMessage", message); } } return new ModelAndView(getViewName()); }
From source file:org.apereo.portal.jdbc.DatabaseMetaDataImpl.java
/** * Gets meta data about the connection.//from w w w .ja v a 2 s . c om */ private void getMetaData(final Connection conn) { try { final DatabaseMetaData dmd = conn.getMetaData(); this.databaseProductName = dmd.getDatabaseProductName(); this.databaseProductVersion = dmd.getDatabaseProductVersion(); this.driverName = dmd.getDriverName(); this.driverVersion = dmd.getDriverVersion(); this.userName = dmd.getUserName(); this.dbUrl = dmd.getURL(); this.dbmdSupportsOuterJoins = dmd.supportsOuterJoins(); } catch (SQLException sqle) { LOG.error("Error getting database meta data.", sqle); } }
From source file:com.manydesigns.portofino.model.database.ConnectionProvider.java
public void init(DatabasePlatformsRegistry databasePlatformsRegistry) { Connection conn = null;/*from w w w . j a v a2 s . c o m*/ ResultSet typeRs = null; String databaseName = getDatabase().getDatabaseName(); try { conn = acquireConnection(); DatabaseMetaData metadata = conn.getMetaData(); databaseProductName = metadata.getDatabaseProductName(); databaseProductVersion = metadata.getDatabaseProductVersion(); try { databaseMajorVersion = metadata.getDatabaseMajorVersion(); databaseMinorVersion = metadata.getDatabaseMinorVersion(); databaseMajorMinorVersion = MessageFormat.format("{0}.{1}", databaseMajorVersion, databaseMinorVersion); } catch (SQLException e) { databaseMajorMinorVersion = e.getMessage(); } driverName = metadata.getDriverName(); driverVersion = metadata.getDriverVersion(); driverMajorVersion = metadata.getDriverMajorVersion(); driverMinorVersion = metadata.getDriverMinorVersion(); driverMajorMinorVersion = MessageFormat.format("{0}.{1}", driverMajorVersion, driverMinorVersion); try { JDBCMajorVersion = metadata.getJDBCMajorVersion(); JDBCMinorVersion = metadata.getJDBCMinorVersion(); JDBCMajorMinorVersion = MessageFormat.format("{0}.{1}", JDBCMajorVersion, JDBCMinorVersion); } catch (Throwable e) { JDBCMajorMinorVersion = e.getMessage(); } // extract supported types types.clear(); typeRs = metadata.getTypeInfo(); while (typeRs.next()) { readType(typeRs); } fixMissingTypeAliases(types); Collections.sort(types, new TypeComparator()); databasePlatform = databasePlatformsRegistry.findApplicableAbstraction(this); if (databasePlatform == null) { status = STATUS_ERROR; errorMessage = MessageFormat.format("Database platform not found for {0}", databaseProductName); logger.warn(errorMessage); } else { status = STATUS_CONNECTED; errorMessage = null; } } catch (Throwable e) { status = STATUS_ERROR; errorMessage = e.getMessage(); logger.warn("Could not create database platform for " + databaseName, e); } finally { DbUtil.closeResultSetAndStatement(typeRs); releaseConnection(conn); lastTested = new Date(); } }