List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:ems.util.DataHandler.java
public static List<MyModel> getDashboardData(String reportType) { List<MyModel> myModels = new LinkedList<>(); String sqlQuery = ""; switch (reportType) { case "1": sqlQuery = Q_S_DASHBOARD_CAST_WISE; break;/*from w w w. j ava 2s .co m*/ case "2": sqlQuery = Q_S_DASHBOARD_GENDER_WISE; break; case "3": sqlQuery = Q_S_DASHBOARD_COLOR_WISE; break; } Connection con = getConnection(); Statement s = null; ResultSet rs = null; try { s = con.createStatement(); rs = s.executeQuery(sqlQuery); while (rs.next()) { myModels.add(new MyModel(rs.getString(1), rs.getString(2))); } } catch (Exception e) { log.error("getDashboardData: " + e.getMessage()); } finally { try { if (rs != null) { rs.close(); } if (s != null) { s.close(); } if (con != null) { con.close(); } } catch (SQLException ex) { log.error("getDashboardData: " + ex.getMessage()); } } return myModels; }
From source file:ems.util.DataHandler.java
public static List<MyModelSimpleStringProperty> getReportDetails(String reportType, String... params) { List<MyModelSimpleStringProperty> reportDetails = new LinkedList<>(); String sqlQuery = ""; switch (reportType) { case "101": sqlQuery = String.format(Q_S_SURNAME_STATUS_, params[0]); break;/*from w ww.j a v a 2 s . c om*/ case "102": sqlQuery = String.format(Q_S_COMMUNITY_STATUS_, params[0]); break; case "3": sqlQuery = String.format(Q_S_AREA_WISE_, params[0], params[1]); break; case "6": sqlQuery = String.format(Q_S_BOOTH_WISE_, params[1]); break; case "7": sqlQuery = String.format(Q_S_COMMUNITY_WISE_, params[0], params[1]); break; case "8": String colorCode = ""; switch (params[1]) { case "Our": colorCode = "1"; break; case "Opposite": colorCode = "2"; break; case "Unpredictable": colorCode = "3"; break; case "Others": colorCode = "4"; break; case "All": colorCode = "5"; break; } sqlQuery = String.format(Q_S_COLOR_CODE_BOOTH_WISE_, params[0], colorCode, colorCode); break; case "9": colorCode = ""; switch (params[1]) { case "Our": colorCode = "1"; break; case "Opposite": colorCode = "2"; break; case "Unpredictable": colorCode = "3"; break; case "Others": colorCode = "4"; break; case "All": colorCode = "5"; break; } sqlQuery = String.format(Q_S_COLOR_CODE_WISE_, colorCode, colorCode); break; case "11": sqlQuery = String.format(Q_S_SETION_WISE_, params[0], params[1]); break; case "12": sqlQuery = String.format(Q_S_SURNAME_WISE_, params[0], params[1]); break; } Connection con = getConnection(); Statement s = null; ResultSet rs = null; try { log.info("sqlQuery:" + sqlQuery); s = con.createStatement(); rs = s.executeQuery(sqlQuery); while (rs.next()) { reportDetails.add(new MyModelSimpleStringProperty(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7), rs.getString(8), rs.getString(9), rs.getString(10), rs.getString(11), "", "", "", "", "")); } } catch (SQLException e) { log.error("getReportDetails: " + e.getMessage()); } finally { try { if (rs != null) { rs.close(); } if (s != null) { s.close(); } if (con != null) { con.close(); } } catch (SQLException ex) { log.error("getBoothList: " + ex.getMessage()); } } return reportDetails; }
From source file:com.aurel.track.dbase.MigrateTo37.java
private static void upgtadeID_TableEntries(Connection connection, int transactionID, int fieldChangeID) { try {/*w ww .j a v a 2 s . c o m*/ Statement stmt = connection.createStatement(); stmt.executeUpdate( "UPDATE ID_TABLE SET NEXT_ID = " + transactionID + " WHERE TABLE_NAME = 'THISTORYTRANSACTION'"); } catch (SQLException e) { LOGGER.error("Updating the THISTORYTRANSACTION ID in ID_TABLE failed with " + e.getMessage()); System.err.println(ExceptionUtils.getStackTrace(e)); } try { Statement stmt = connection.createStatement(); stmt.executeUpdate( "UPDATE ID_TABLE SET NEXT_ID = " + fieldChangeID + " WHERE TABLE_NAME = 'TFIELDCHANGE'"); } catch (SQLException e) { LOGGER.error("Updating the TFIELDCHANGE ID in ID_TABLE failed with " + e.getMessage()); System.err.println(ExceptionUtils.getStackTrace(e)); } }
From source file:edu.lternet.pasta.dml.DataManager.java
public static Connection getConnection() throws SQLException { Connection connection = null; int index = 0; if (connectionPool == null) { throw new SQLException("The Connection Pool is null"); }/*from ww w . jav a 2 s . c o m*/ while (index < MAXIMUM_NUMBER_TO_ACCESS_CONNECTIONPOOL) { try { connection = connectionPool.getConnection(); break; } catch (ConnectionNotAvailableException cna) { try { Thread.sleep(SLEEP_TIME); } catch (Exception e) { log.error("Error in DataManager.getConnection(): " + e.getMessage()); } } catch (SQLException sql) { log.error("Error in DataManager.getConnection(): " + sql.getMessage()); } index++; } return connection; }
From source file:com.google.visualization.datasource.util.SqlDataSourceHelper.java
/** * Executes the given query on the given SQL database table, and returns the * result as a DataTable.//from w ww.j a va 2 s . c o m * * @param query The query. * @param databaseDescription The information needed to connect to the SQL database and table. * * @return DataTable A data table with the data from the specified sql table, * after applying the specified query on it. * * @throws DataSourceException Thrown when the data source fails to perform the action. */ public static DataTable executeQuery(Query query, SqlDatabaseDescription databaseDescription) throws DataSourceException { Connection con = getDatabaseConnection(databaseDescription); String tableName = databaseDescription.getTableName(); // Build the sql query. StrBuilder queryStringBuilder = new StrBuilder(); buildSqlQuery(query, queryStringBuilder, tableName); List<String> columnIdsList = null; if (query.hasSelection()) { columnIdsList = getColumnIdsList(query.getSelection()); } Statement stmt = null; try { // Execute the sql query. stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(queryStringBuilder.toString()); DataTable table = buildColumns(rs, columnIdsList); // Fill the data in the data table. buildRows(table, rs); return table; } catch (SQLException e) { String messageToUser = "Failed to execute SQL query: " + "\"" + queryStringBuilder.toString() + "\"\n" + "SQL error message: " + e.getMessage(); throw new DataSourceException(ReasonType.INTERNAL_ERROR, messageToUser); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException e) { /* ignore close errors */ } } if (con != null) { try { con.close(); } catch (SQLException e) { /* ignore close errors */ } } } }
From source file:com.wso2telco.gsma.authenticators.DBUtils.java
public static void insertHashKeyContextIdentifierMapping(String hashKey, String contextIdentifier) throws AuthenticatorException { String sql = "insert into sms_hashkey_contextid_mapping(hashkey, contextid) values (?,?);"; if (log.isDebugEnabled()) { log.debug("Executing the query " + sql + " for hash key " + hashKey + " and context identifier " + contextIdentifier);/*from w w w.j a v a2 s. co m*/ } Connection connection = null; PreparedStatement ps = null; try { connection = getConnectDBConnection(); ps = connection.prepareStatement(sql.toString()); ps.setString(1, hashKey); ps.setString(2, contextIdentifier); ps.executeUpdate(); } catch (SQLException e) { handleException(e.getMessage(), e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, null, ps); } }
From source file:com.aurel.track.dbase.MigrateTo37.java
private static void addLongTextFieldChange(PreparedStatement pstmtLongText, Integer fieldChangeID, Integer transactionID, String description) { try {// ww w. j a v a2 s .co m pstmtLongText.setInt(1, fieldChangeID); pstmtLongText.setInt(2, TFieldChangeBean.COMPOUND_HISTORY_FIELD); pstmtLongText.setInt(3, transactionID); pstmtLongText.setString(4, description); pstmtLongText.setInt(5, ValueType.LONGTEXT); pstmtLongText.setString(6, UUID.randomUUID().toString()); pstmtLongText.executeUpdate(); } catch (SQLException e) { LOGGER.error("Adding a field change for long text with transactionID " + transactionID + " fieldChangeID " + fieldChangeID + " failed with " + e.getMessage(), e); System.err.println(ExceptionUtils.getStackTrace(e)); } }
From source file:gsn.http.restapi.RequestHandler.java
public static Map<String, Double> getMostRecentValueFor(String virtual_sensor_name) { StringBuilder query = new StringBuilder("select * from ").append(virtual_sensor_name) .append(" where timed = (select max(timed) from ").append(virtual_sensor_name).append(")"); Map<String, Double> toReturn = new HashMap<String, Double>(); try {//from w w w. java 2 s.co m DataEnumerator result = Main.getStorage(virtual_sensor_name).executeQuery(query, true); if (result.hasMoreElements()) { StreamElement se = result.nextElement(); //toReturn.put("timed", se.getTimeStamp()); for (String fn : se.getFieldNames()) { toReturn.put(fn.toLowerCase(), (Double) se.getData(fn)); } } } catch (SQLException e) { logger.error("ERROR IN EXECUTING, query: " + query); logger.error(e.getMessage(), e); return null; } return toReturn; }
From source file:com.flexive.core.Database.java
/** * Retrieves a database connection.// w w w .ja v a 2 s .c om * * @param divisionId the requested division Id * @return a database connection * @throws SQLException If no connection could be retrieved */ public static Connection getDbConnection(int divisionId) throws SQLException { // Try to obtain a connection try { return getDataSource(divisionId, true).getConnection(); } catch (SQLException exc) { String sErr = "FxDbException, unable to retrieve DB Connection: " + exc.getMessage(); LOG.error(sErr); throw new SQLException(sErr); } }
From source file:com.flexive.core.Database.java
/** * Retrieves a database connection for the global configuration table, regardless * of the current request's division id. * * @return a database connection// w w w. ja v a2 s . co m * @throws SQLException if no connection could be retrieved */ public static Connection getGlobalDbConnection() throws SQLException { try { return getGlobalDataSource().getConnection(); } catch (SQLException exc) { String sErr = "FxDbException, unable to retrieve global DB Connection: " + exc.getMessage(); LOG.error(sErr); throw new SQLException(sErr); } }