List of usage examples for java.sql DatabaseMetaData getDatabaseProductName
String getDatabaseProductName() throws SQLException;
From source file:org.talend.metadata.managment.utils.MetadataConnectionUtils.java
public static boolean isOdbcExcel(DatabaseMetaData connectionMetadata) throws SQLException { if (connectionMetadata.getDriverName() != null && connectionMetadata.getDriverName().toLowerCase().startsWith(DatabaseConstant.ODBC_DRIVER_NAME) && connectionMetadata.getDatabaseProductName() != null && connectionMetadata.getDatabaseProductName().equals(DatabaseConstant.ODBC_EXCEL_PRODUCT_NAME)) { return true; }/*w ww . j a va 2 s .c o m*/ return false; }
From source file:org.talend.metadata.managment.utils.MetadataConnectionUtils.java
public static boolean isOdbcPostgresql(DatabaseMetaData connectionMetadata) throws SQLException { if (connectionMetadata.getDriverName() != null && connectionMetadata.getDriverName().toLowerCase().startsWith(DatabaseConstant.ODBC_DRIVER_NAME) && connectionMetadata.getDatabaseProductName() != null && connectionMetadata.getDatabaseProductName().toLowerCase() .indexOf(DatabaseConstant.POSTGRESQL_PRODUCT_NAME) > -1) { return true; }//w w w. j a v a 2s . co m return false; }
From source file:org.apache.drill.jdbc.ITTestShadedJar.java
@Test public void testDatabaseVersion() throws Exception { // print class path for debugging System.out.println("java.class.path:"); System.out.println(System.getProperty("java.class.path")); final URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); method.setAccessible(true);//from w ww . jav a2 s.co m method.invoke(loader, getJdbcUrl()); Class<?> clazz = loader.loadClass("org.apache.drill.jdbc.Driver"); try { Driver driver = (Driver) clazz.newInstance(); try (Connection c = driver.connect("jdbc:drill:drillbit=localhost:31010", null)) { DatabaseMetaData metadata = c.getMetaData(); assertEquals("Apache Drill JDBC Driver", metadata.getDriverName()); assertEquals("Apache Drill Server", metadata.getDatabaseProductName()); //assertEquals() } } catch (Exception ex) { throw ex; } }
From source file:com.jaspersoft.jasperserver.api.engine.common.virtualdatasourcequery.VirtualSQLDataSource.java
private void testConnection() throws SQLException { DatabaseMetaData dbMetaData = connection.getMetaData(); System.out.println("MetaDataConstants.DATASOURCE_VENDOR = [" + dbMetaData.getDatabaseProductName() + "]"); System.out.println("MetaDataConstants.NAME_QUOTE_CHAR = [" + dbMetaData.getIdentifierQuoteString() + "]"); Set set = discoverSchemas(connection); for (Object val : set) System.out.println("SCHEMA = " + val); }
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 w w w. ja va 2s . com*/ 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.talend.cwm.db.connection.ConnectionUtils.java
/** * Comment method "isDB2"./*from w ww .j a v a 2s . c om*/ * * @param metadata * @return * @throws SQLException */ public static boolean isDB2(DatabaseMetaData metadata) throws SQLException { if (metadata != null && metadata.getDatabaseProductName() != null && metadata.getDatabaseProductName().indexOf(DatabaseConstant.IBM_DB2_ZOS_PRODUCT_NAME) > -1) { return true; } return false; }
From source file:org.wso2.carbon.identity.application.common.persistence.IdentityApplicationDBInitializer.java
private String getDatabaseType(Connection conn) throws IdentityApplicationManagementException { String type = null;// www . j a v a 2 s .c om try { if (conn != null && (!conn.isClosed())) { DatabaseMetaData metaData = conn.getMetaData(); String databaseProductName = metaData.getDatabaseProductName(); if (databaseProductName.matches("(?i).*mysql.*")) { type = "mysql"; } else if (databaseProductName.matches("(?i).*oracle.*")) { type = "oracle"; } else if (databaseProductName.matches("(?i).*microsoft.*")) { type = "mssql"; } else if (databaseProductName.matches("(?i).*h2.*")) { type = "h2"; } else if (databaseProductName.matches("(?i).*db2.*")) { type = "db2"; } else if (databaseProductName.matches("(?i).*postgresql.*")) { type = "postgresql"; } } else { String msg = "Illegal arguments: Connection is either \'NULL\' or already closed"; log.debug(msg); throw new IllegalArgumentException(msg); } } catch (SQLException e) { log.error(e.getMessage(), e); String msg = "Failed to create Identity Application Management Database"; throw new IdentityApplicationManagementException(msg); } return type; }
From source file:za.co.eon.econtentsolutions.component.abstractlticomponent.AbstractLTIComponentServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w .j a va2 s. c o 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:com.alibaba.dubbo.governance.status.DatabaseStatusChecker.java
public Status check() { boolean ok;/*ww w.ja va2 s. co 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); }