List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:com.novartis.opensource.yada.util.YADAUtils.java
/** * One-liner execution of a sql statement, returning an SQL {@link java.sql.ResultSet}. * <strong>Note: This method opens a db connection but DOES NOT CLOSE IT. * Use the static method {@link ConnectionFactory#releaseResources(ResultSet)} to close it from * the calling method</strong>//from w w w. java 2 s .c o m * @param sql the query to execute * @param params the data values to map to query columns * @return a {@link java.sql.ResultSet} object containing the result of the query * @throws YADAConnectionException when the datasource is inaccessible * @throws YADASQLException when the JDBC configuration or execution fails */ public static ResultSet executePreparedStatement(String sql, Object[] params) throws YADAConnectionException, YADASQLException { ResultSet rs = null; try { Connection c = ConnectionFactory.getConnectionFactory().getConnection(ConnectionFactory.YADA_APP); PreparedStatement p = c.prepareStatement(sql); for (int i = 1; i <= params.length; i++) { Object param = params[i - 1]; if (param instanceof String) { p.setString(i, (String) param); } else if (param instanceof Date) { p.setDate(i, (Date) param); } else if (param instanceof Integer) { p.setInt(i, ((Integer) param).intValue()); } else if (param instanceof Float) { p.setFloat(i, ((Float) param).floatValue()); } } rs = p.executeQuery(); } catch (SQLException e) { throw new YADASQLException(e.getMessage(), e); } return rs; }
From source file:com.wso2telco.core.dbutils.DbUtils.java
/** * Close result set.//from w ww . j a va 2 s. c o m * * @param resultSet * the result set */ private static void closeResultSet(ResultSet resultSet) { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { log.warn("Database error. Could not close ResultSet - " + e.getMessage(), e); } } }
From source file:net.pms.database.TableMusicBrainzReleases.java
/** * Stores the MBID with information from this {@link Tag} in the database * * @param mBID the MBID to store/*from w w w. j a va2 s.c o m*/ * @param tag the {@link Tag} who's information should be associated with * the given MBID */ public static void writeMBID(final String mBID, final CoverArtArchiveTagInfo tagInfo) { boolean trace = LOGGER.isTraceEnabled(); try (Connection connection = database.getConnection()) { String query = "SELECT * FROM " + TABLE_NAME + constructTagWhere(tagInfo, true); if (trace) { LOGGER.trace("Searching for release MBID with \"{}\" before update", query); } tableLock.writeLock().lock(); try (Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { connection.setAutoCommit(false); try (ResultSet result = statement.executeQuery(query)) { if (result.next()) { if (StringUtil.hasValue(mBID) || !StringUtil.hasValue(result.getString("MBID"))) { if (trace) { LOGGER.trace("Updating row {} to MBID \"{}\"", result.getInt("ID"), mBID); } result.updateTimestamp("MODIFIED", new Timestamp(System.currentTimeMillis())); if (StringUtil.hasValue(mBID)) { result.updateString("MBID", mBID); } else { result.updateNull("MBID"); } result.updateRow(); } else if (trace) { LOGGER.trace("Leaving row {} alone since previous information seems better", result.getInt("ID")); } } else { if (trace) { LOGGER.trace( "Inserting new row for MBID \"{}\":\n" + " Artist \"{}\"\n" + " Album \"{}\"\n" + " Title \"{}\"\n" + " Year \"{}\"\n" + " Artist ID \"{}\"\n" + " Track ID \"{}\"\n", mBID, tagInfo.artist, tagInfo.album, tagInfo.title, tagInfo.year, tagInfo.artistId, tagInfo.trackId); } result.moveToInsertRow(); result.updateTimestamp("MODIFIED", new Timestamp(System.currentTimeMillis())); if (StringUtil.hasValue(mBID)) { result.updateString("MBID", mBID); } if (StringUtil.hasValue(tagInfo.album)) { result.updateString("ALBUM", left(tagInfo.album, 1000)); } if (StringUtil.hasValue(tagInfo.artist)) { result.updateString("ARTIST", left(tagInfo.artist, 1000)); } if (StringUtil.hasValue(tagInfo.title)) { result.updateString("TITLE", left(tagInfo.title, 1000)); } if (StringUtil.hasValue(tagInfo.year)) { result.updateString("YEAR", left(tagInfo.year, 20)); } if (StringUtil.hasValue(tagInfo.artistId)) { result.updateString("ARTIST_ID", tagInfo.artistId); } if (StringUtil.hasValue(tagInfo.trackId)) { result.updateString("TRACK_ID", tagInfo.trackId); } result.insertRow(); } } finally { connection.commit(); } } finally { tableLock.writeLock().unlock(); } } catch (SQLException e) { LOGGER.error("Database error while writing Music Brainz ID \"{}\" for \"{}\": {}", mBID, tagInfo, e.getMessage()); LOGGER.trace("", e); } }
From source file:com.liferay.sync.engine.service.SyncAccountService.java
public static SyncAccount fetchSyncAccount(long syncAccountId) { try {/*from w ww .j av a 2s.c om*/ return _syncAccountPersistence.queryForId(syncAccountId); } catch (SQLException sqle) { if (_logger.isDebugEnabled()) { _logger.debug(sqle.getMessage(), sqle); } return null; } }
From source file:com.liferay.sync.engine.service.SyncAccountService.java
public static SyncAccount fetchSyncAccount(String uuid) { try {// w w w . j a v a 2 s .c o m return _syncAccountPersistence.fetchByUuid(uuid); } catch (SQLException sqle) { if (_logger.isDebugEnabled()) { _logger.debug(sqle.getMessage(), sqle); } return null; } }
From source file:com.liferay.sync.engine.service.SyncAccountService.java
public static List<SyncAccount> findAll() { try {/*from w w w .j a v a 2 s . c o m*/ return _syncAccountPersistence.queryForAll(); } catch (SQLException sqle) { if (_logger.isDebugEnabled()) { _logger.debug(sqle.getMessage(), sqle); } return Collections.emptyList(); } }
From source file:com.liferay.sync.engine.service.SyncAccountService.java
public static List<SyncAccount> findSyncAccounts(String lanServerUuid) { try {// w ww . j a v a 2s .com return _syncAccountPersistence.findByLanServerUuid(lanServerUuid); } catch (SQLException sqle) { if (_logger.isDebugEnabled()) { _logger.debug(sqle.getMessage(), sqle); } return null; } }
From source file:com.hp.test.framework.generatejellytess.GenerateJellyTests.java
public static void exemappingmodel() { boolean clean_files = false; Map<Integer, String> Master_ModelList = new HashMap<Integer, String>(); try {/*from www . jav a 2s . c om*/ Class.forName("org.sqlite.JDBC"); log.info("TestCase DB Location" + mp.getProperty("MODEL_DB_LOCATION")); alm_test_location = mp.getProperty("ALM_FORMAT_STORE_LOC"); Jelly_Tests_location = mp.getProperty("JELLY_TESTS_LOCATION"); CLEAN_JELLY_TESTS = mp.getProperty("CLEAN_JELLY_TESTS"); if (CLEAN_JELLY_TESTS.toLowerCase().equals("yes")) { clean_files = true; } connection = DriverManager.getConnection("jdbc:sqlite:" + mp.getProperty("MODEL_DB_LOCATION")); // int GID_int = Integer.parseInt(GID); Statement Master_statement = connection.createStatement(); ResultSet rs_master = Master_statement.executeQuery( "SELECT GID,FEATURENAME FROM DM_MASTERMODELXML_REF WHERE TESTCASE_GEN_STATUS LIKE 'COMPLETED' AND JELLYCASE_GEN_STATUS IS NULL ORDER BY GID"); while (rs_master.next()) { Master_ModelList.put(rs_master.getInt("GID"), rs_master.getString("FEATURENAME")); } rs_master = null; Master_statement = null; // connection.close(); } catch (SQLException e) { log.error("Error in getting data from DM_MASTERMODELXML_REF table to generate Jelly and ALM TESTS"); } catch (ClassNotFoundException e) { log.error("Exception in exemapping model function" + e.getMessage()); } if (Master_ModelList.isEmpty()) { log.info( "********************************************************************************************************************************************"); log.info( "Jelly Testcases are already generated for all the Models; Please check the column status \"JELLYCASE_GEN_STATUS\" in \"DM_MASTERMODELXML_REF\""); log.info( "********************************************************************************************************************************************"); throw new RuntimeException("Runtime Exception"); // System.exit(0); } for (int key : Master_ModelList.keySet()) { GenerateJellyTests.CreateJellyTestsFolder(Jelly_Tests_location, clean_files, Master_ModelList.get(key)); temp_jelly_Tests_location = Jelly_Tests_location + Master_ModelList.get(key); glb_Feature_Name = Master_ModelList.get(key); log.info("Started generating Jelly Tests for the Feature::" + glb_Feature_Name); log.info("***************************************************"); genjellyTests(String.valueOf(key), Master_ModelList.get(key)); try { DatabaseUtils.UpdateSingleValue("DM_MASTERMODELXML_REF", "COMPLETED", "JELLYCASE_GEN_STATUS", "GID", String.valueOf(key)); } catch (ClassNotFoundException e) { log.error("Exception in updating DM_MASTERMODELXML_REF table" + e.getMessage()); } log.info("End of generating Jelly Tests for the Feature::" + glb_Feature_Name); } }
From source file:com.liferay.sync.engine.service.SyncAccountService.java
public static SyncAccount fetchSyncAccountByFilePathName(String filePathName) { try {/* www . jav a 2s. c o m*/ return _syncAccountPersistence.fetchByFilePathName(filePathName); } catch (SQLException sqle) { if (_logger.isDebugEnabled()) { _logger.debug(sqle.getMessage(), sqle); } return null; } }
From source file:com.liferay.sync.engine.service.SyncAccountService.java
public static SyncAccount update(SyncAccount syncAccount) { try {//from ww w.j a v a 2 s . co m _syncAccountPersistence.createOrUpdate(syncAccount); return syncAccount; } catch (SQLException sqle) { if (_logger.isDebugEnabled()) { _logger.debug(sqle.getMessage(), sqle); } return null; } }