List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:com.xeiam.yank.Yank.java
/** * Handles exceptions and logs them//from ww w. j av a 2 s . c o m * * @param e the SQLException */ private static void handleSQLException(SQLException e) { if (e.getMessage().startsWith("Cannot create")) { logger.error(BEAN_EXCEPTION_MESSAGE, e); } else { logger.error(QUERY_EXCEPTION_MESSAGE, e); } }
From source file:CachedConnectionServlet.java
synchronized private static void checkUse() { CachedConnection cached = null;//w ww . jav a 2 s .co m Connection conn = null; int i = 0; long now = System.currentTimeMillis(); long then = 0; for (i = numberConnections - 1; i > -1; i--) { if (verbose) { System.out.println( "CacheConnection monitor checking vector entry " + Integer.toString(i) + " for use..."); } cached = (CachedConnection) cachedConnections.get(i); if (!cached.isInUse()) { then = cached.getLastUsed(); if ((now - then) > MAX_IDLE) { if (verbose) { System.out .println("Cached entry " + Integer.toString(i) + " idle too long, being destroyed"); } conn = cached.getConnection(); try { conn.close(); } catch (SQLException e) { System.err.println("Unable to close connection: " + e.getMessage()); } cachedConnections.remove(i); numberConnections--; } } } }
From source file:com.trackplus.ddl.DataWriter.java
private static void executeUpdate(Connection con, Statement stmt, String s) throws DDLException { try {/*from ww w . ja va 2 s. com*/ stmt.executeUpdate(s); } catch (SQLException e) { LOGGER.error("Error execute script line:" + e.getMessage()); LOGGER.warn("-------------\n\n"); LOGGER.warn(s); LOGGER.warn("-------------\n\n"); if (LOGGER.isDebugEnabled()) { LOGGER.debug(ExceptionUtils.getStackTrace(e)); } try { stmt.close(); con.rollback(); con.setAutoCommit(true); } catch (SQLException ex) { throw new DDLException(e.getMessage(), e); } throw new DDLException(e.getMessage(), e); } }
From source file:es.tekniker.framework.ktek.commons.mng.db.CommonsLoadFile.java
public static boolean loadData(List<String> data) { boolean boolOK = true; PersistentSession session = null;/*from ww w. j a va 2 s . c o m*/ PersistentTransaction tr = null; Statement st; StringBuffer sql = null; String[] dataline = null; String tablename = null; boolean boolExec = false; try { session = KTEKPersistentManager.instance().getSession(); tr = session.beginTransaction(); try { st = session.connection().createStatement(); System.out.println(data.size()); for (int i = 0; i < data.size(); i++) { dataline = data.get(i).split(";"); log.debug("data by line " + data.get(i) + " num items " + dataline.length + " data line 0 " + dataline[0]); tablename = dataline[0]; tablename = tablename.trim(); sql = null; if (tablename.equals(TABLE_ktek_language)) { log.debug("language "); sql = getSQL4TABLE_LANGUAGE(dataline); } else if (tablename.equals(TABLE_ktek_tpsettings)) sql = getSQL4TABLE_TPSETTINGS(dataline); else if (tablename.equals(TABLE_ktek_pathology)) sql = getSQL4TABLE_PATHOLOGY(dataline); else if (tablename.equals(TABLE_ktek_translation_text)) sql = getSQL4TABLE_TRANSLATION_TEXT(dataline); else if (tablename.equals(TABLE_ktek_user)) sql = getSQL4TABLE_USER(dataline); else if (tablename.equals(TABLE_ktek_user_ext)) sql = getSQL4TABLE_USER_EXT(dataline); else if (tablename.equals(TABLE_ktek_usersessiondata)) sql = getSQL4TABLE_USERSESSIONDATA(dataline); else { log.debug("table name not found " + dataline[0]); } //log.debug(sql); log.debug("i : " + i + " SQL : " + sql); if (sql != null) { boolExec = st.execute(sql.toString()); log.debug(" executed " + boolExec); } } } catch (SQLException e) { // TODO Auto-generated catch block log.debug(" SQLException " + e.getMessage()); e.printStackTrace(); boolOK = false; } //if(boolOK) tr.commit(); session.close(); } catch (PersistentException e) { // TODO Auto-generated catch block e.printStackTrace(); } return boolOK; }
From source file:com.taobao.tddl.jdbc.group.util.ExceptionUtils.java
public static void throwSQLException(SQLException exception, String sql, Map<Integer, ParameterContext> parameter) throws SQLException { if (sql != null) { log.info(("TDDL SQL EXECUTE ERROR REPORTER:" + getErrorContext(sql, parameter, SQL_EXECUTION_ERROR_CONTEXT_MESSAGE)) + "nest Exceptions is " + exception.getMessage(), exception); }/*ww w .j ava2 s . co m*/ throw exception; }
From source file:com.cws.esolutions.security.utils.DAOInitializer.java
/** * @param properties - The <code>AuthRepo</code> object containing connection information * @param isContainer - A <code>boolean</code> flag indicating if this is in a container * @param bean - The {@link com.cws.esolutions.security.SecurityServiceBean} <code>SecurityServiceBean</code> that holds the connection */// ww w . ja va 2 s . co m public synchronized static void closeAuthConnection(final InputStream properties, final boolean isContainer, final SecurityServiceBean bean) { String methodName = DAOInitializer.CNAME + "#closeAuthConnection(final InputStream properties, final boolean isContainer, final SecurityServiceBean bean)"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("InputStream: {}", properties); DEBUGGER.debug("isContainer: {}", isContainer); DEBUGGER.debug("SecurityServiceBean: {}", bean); } try { Properties connProps = new Properties(); connProps.load(properties); if (DEBUG) { DEBUGGER.debug("Properties: {}", connProps); } AuthRepositoryType repoType = AuthRepositoryType .valueOf(connProps.getProperty(DAOInitializer.REPO_TYPE)); if (DEBUG) { DEBUGGER.debug("AuthRepositoryType: {}", repoType); } switch (repoType) { case LDAP: LDAPConnectionPool ldapPool = (LDAPConnectionPool) bean.getAuthDataSource(); if (DEBUG) { DEBUGGER.debug("LDAPConnectionPool: {}", ldapPool); } if ((ldapPool != null) && (!(ldapPool.isClosed()))) { ldapPool.close(); } break; case SQL: // the isContainer only matters here if (!(isContainer)) { BasicDataSource dataSource = (BasicDataSource) bean.getAuthDataSource(); if (DEBUG) { DEBUGGER.debug("BasicDataSource: {}", dataSource); } if ((dataSource != null) && (!(dataSource.isClosed()))) { dataSource.close(); } } break; case NONE: return; default: return; } } catch (SQLException sqx) { ERROR_RECORDER.error(sqx.getMessage(), sqx); } catch (FileNotFoundException fnfx) { ERROR_RECORDER.error(fnfx.getMessage(), fnfx); } catch (IOException iox) { ERROR_RECORDER.error(iox.getMessage(), iox); } }
From source file:net.firejack.platform.core.utils.db.DBUtils.java
private static void insertDataToTargetTable(TablesMapping mapping, Connection sourceConnection, Connection targetConnection) throws SQLException { Map<Column, Column> columnMapping = mapping.getColumnMapping(); if (columnMapping.isEmpty()) { logger.warn("No columns are detected - no data to insert."); } else {//ww w .ja va2 s . c om ResultSet rs = selectDataFromSource(sourceConnection, mapping); String insertQuery = populateInsertQuery(mapping); PreparedStatement insertStatement = targetConnection.prepareStatement(insertQuery); targetConnection.setAutoCommit(false); try { int currentStep = 1; while (rs.next()) { for (int i = 1; i <= columnMapping.size(); i++) { insertStatement.setObject(i, rs.getObject(i)); } insertStatement.addBatch(); if (++currentStep > DEFAULT_BATCH_SIZE) { insertStatement.executeBatch(); targetConnection.commit(); currentStep = 1; } } if (currentStep != 1) { insertStatement.executeBatch(); targetConnection.commit(); } } catch (SQLException e) { logger.error(e.getMessage(), e); targetConnection.rollback(); } finally { insertStatement.close(); rs.close(); } } }
From source file:com.hp.test.framework.generatejellytess.GenerateJellyTests.java
public static void genjellyTests(String Parent_model_gid, String Feature_name) { Statement statement = null;/*from ww w .ja va 2 s . c o m*/ try { statement = connection.createStatement(); String sql_query = "SELECT DR.GID as MODEL_GID,DSR.GID AS SCENARIO_GID,DT.GID AS TEST_GID,DR.MODEL_PATH,DT.TESTCASE,DT.RESULTS FROM DM_TESTCASE DT, DM_MODELXML_REF DR, DM_SCENARIO_REF DSR where DT.TEMPLATE_GID=DSR.GID and DSR.MODEL_GID_REF=DR.GID AND DR.MASTER_GID=" + Integer.parseInt(Parent_model_gid) + " ORDER BY DR.GID"; ResultSet rs = statement.executeQuery(sql_query); String GID_temp = ""; String Test_case = ""; String Model_xml_path = ""; int results = 0; CreateReadableTestCase.fw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(alm_test_location + Feature_name + ".csv"), "UTF-8")); CreateReadableTestCase.fw.write("TestCaseNumber,StepName,Step Description,ExpectedResults\n"); while (rs.next()) { GID_temp = Parent_model_gid + "_" + rs.getString("MODEL_GID") + "_" + rs.getString("SCENARIO_GID") + "_" + rs.getString("TEST_GID"); // rs.getInt("GID"); log.info("Generating Jelly Testcase for MasterModel GID::" + Parent_model_gid + " MODEL XML GID::" + rs.getString("MODEL_GID") + " TEST SCENARIO GID::" + rs.getString("SCENARIO_GID") + " TESTCASE GID::" + rs.getString("TEST_GID")); Test_case = rs.getString("TESTCASE"); results = rs.getInt("RESULTS"); Model_xml_path = rs.getString("MODEL_PATH"); maptestcasesapi(GID_temp, Test_case, results, Model_xml_path); // break; } CreateReadableTestCase.fw.close(); CreateReadableTestCase.fw = null; statement.setQueryTimeout(30); // set timeout to 30 sec. if (statement != null) { statement.close(); } } catch (SQLException e) { log.error("Error in getting records from DM_TESTCASE to Execute API or to generate Jelly tests"); } catch (IOException e) { log.error("exception in IO" + e.getMessage()); } catch (ClassNotFoundException e) { log.error("" + e.getMessage()); } }
From source file:net.firejack.platform.core.utils.db.DBUtils.java
public static void migrateData(OpenFlameDataSource source, OpenFlameDataSource target) { logger.info("Starting migration process"); Connection sourceConnection = null; Connection targetConnection = null; try {//from w w w . j ava2s. c o m sourceConnection = source.getConnection(); targetConnection = target.getConnection(); List<Table> mysqlTables = getTables(sourceConnection, source); List<Table> oracleTables = getTables(targetConnection, target); List<TablesMapping> mappings = mapTables(mysqlTables, oracleTables); if (mappings.size() == mysqlTables.size()) { logger.info("Tables mapped successfully."); for (TablesMapping mapping : mappings) { addLog("Migrate data from [" + mapping.getSourceTable().getName() + "] table.", 1, LogLevel.INFO); insertDataToTargetTable(mapping, sourceConnection, targetConnection); addLog("Data migration from [" + mapping.getSourceTable().getName() + "] completed.", 1, LogLevel.INFO); } } else { logger.warn("Failed to map all tables."); addLog("Failed to migrate data - databases are not identical.", 1, LogLevel.ERROR); } } catch (SQLException e) { logger.error(e.getMessage(), e); addLog(e.getMessage(), 1, LogLevel.ERROR); } finally { if (sourceConnection != null) { try { sourceConnection.close(); } catch (SQLException e) { logger.error(e.getMessage(), e); } } if (targetConnection != null) { try { targetConnection.close(); } catch (SQLException e) { logger.error(e.getMessage(), e); } } } }
From source file:com.trackplus.ddl.DataWriter.java
public static void writeDataToDB(DatabaseInfo databaseInfo, String dirName) throws DDLException { String fileName = dirName + File.separator + DataReader.FILE_NAME_DATA; LOGGER.info("Importing data from file \" " + fileName + "\" to DB \"" + databaseInfo.getUrl() + "\" ..."); Date d1 = new Date(); Properties info = DataWriter.readProperties(dirName + File.separator + DataReader.FILE_NAME_INFO); String sourceDriver = info.getProperty("driver"); String sourceUrl = info.getProperty("url"); String allData = info.getProperty("allData"); String versionTrack = info.getProperty("versionTrack"); String versionDB = info.getProperty("versionDB"); LOGGER.debug("versionTrack=" + versionTrack); LOGGER.debug("versionDB=" + versionDB); LOGGER.debug("sourceDriver=" + sourceDriver); LOGGER.debug("sourceUrl=" + sourceUrl); LOGGER.info("All data to import: " + allData); Connection connection = getConnection(databaseInfo); int idx = 0;/*ww w . ja v a 2 s . com*/ idx = executeScript(fileName, connection); LOGGER.info("Records imported:" + idx + "\n"); String fileNameUpdate = dirName + File.separator + DataReader.FILE_NAME_DATA_UPDATE; LOGGER.info("Execute updates..."); String databaseTypeTarget = MetaDataBL.getDatabaseType(databaseInfo.getUrl()); String databaseTypeSource = MetaDataBL.getDatabaseType(sourceUrl); int countUpdate = 0; boolean sameDatabaseType = databaseTypeSource.equals(databaseTypeTarget); if (sameDatabaseType) { LOGGER.info("Same database type"); String endOfStatement = ";" + DataReader.LINE_SEPARATOR; countUpdate = executeScript(fileNameUpdate, connection, endOfStatement); } else { countUpdate = executeUpdateScript(fileNameUpdate, connection); } LOGGER.info(countUpdate + " updates executed"); LOGGER.info("Importing blob data ...."); int count = importBlobScript(dirName + File.separator + DataReader.FILE_NAME_BLOB, connection); LOGGER.info("Blob record imported:" + count + "\n"); idx = idx + count; try { connection.close(); } catch (SQLException e) { throw new DDLException(e.getMessage(), e); } Date d2 = new Date(); LOGGER.info("Data imported! Insert executed " + idx + ". Time spend: " + (d2.getTime() - d1.getTime()) + " ms!"); }