List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:com.xqdev.sql.MLSQL.java
private static void addExceptions(Element meta, SQLException e) { if (e == null) return;//www . jav a 2 s . com Namespace sql = meta.getNamespace(); Element exceptions = new Element("exceptions", sql); meta.addContent(exceptions); do { exceptions.addContent(new Element("exception", sql).setAttribute("type", e.getClass().getName()) .addContent(new Element("reason", sql).setText(e.getMessage())) .addContent(new Element("sql-state", sql).setText(e.getSQLState())) .addContent(new Element("vendor-code", sql).setText("" + e.getErrorCode()))); e = e.getNextException(); } while (e != null); }
From source file:com.espertech.esper.epl.db.DatabasePollingViewableFactory.java
private static QueryMetaData getExampleQueryMetaData(Connection connection, String[] parameters, String sampleSQL, ColumnSettings metadataSetting, boolean isUsingMetadataSQL) throws ExprValidationException { // Simply add up all input parameters List<String> inputParameters = new LinkedList<String>(); inputParameters.addAll(Arrays.asList(parameters)); Statement statement;/*from w w w . ja v a 2 s.co m*/ try { statement = connection.createStatement(); } catch (SQLException ex) { String text = "Error creating statement"; log.error(text, ex); throw new ExprValidationException(text + ", reason: " + ex.getMessage()); } ResultSet result = null; try { result = statement.executeQuery(sampleSQL); } catch (SQLException ex) { try { statement.close(); } catch (SQLException e) { log.info("Error closing statement: " + e.getMessage(), e); } String text; if (isUsingMetadataSQL) { text = "Error compiling metadata SQL to retrieve statement metadata, using sql text '" + sampleSQL + "'"; } else { text = "Error compiling metadata SQL to retrieve statement metadata, consider using the 'metadatasql' syntax, using sql text '" + sampleSQL + "'"; } log.error(text, ex); throw new ExprValidationException(text + ", reason: " + ex.getMessage()); } Map<String, DBOutputTypeDesc> outputProperties; try { outputProperties = compileResultMetaData(result.getMetaData(), metadataSetting); } catch (SQLException ex) { try { result.close(); } catch (SQLException e) { // don't handle } try { statement.close(); } catch (SQLException e) { // don't handle } String text = "Error in statement '" + sampleSQL + "', failed to obtain result metadata"; log.error(text, ex); throw new ExprValidationException(text + ", please check the statement, reason: " + ex.getMessage()); } finally { if (result != null) { try { result.close(); } catch (SQLException e) { log.warn("Exception closing result set: " + e.getMessage()); } } if (statement != null) { try { statement.close(); } catch (SQLException e) { log.warn("Exception closing result set: " + e.getMessage()); } } } return new QueryMetaData(inputParameters, outputProperties); }
From source file:com.espertech.esper.epl.db.DatabasePollingViewableFactory.java
private static QueryMetaData getPreparedStmtMetadata(Connection connection, String[] parameters, String preparedStatementText, ColumnSettings metadataSetting) throws ExprValidationException { PreparedStatement prepared;//from w w w.j av a2s . com try { if (log.isInfoEnabled()) { log.info(".getPreparedStmtMetadata Preparing statement '" + preparedStatementText + "'"); } prepared = connection.prepareStatement(preparedStatementText); } catch (SQLException ex) { String text = "Error preparing statement '" + preparedStatementText + '\''; log.error(text, ex); throw new ExprValidationException(text + ", reason: " + ex.getMessage()); } // Interrogate prepared statement - parameters and result List<String> inputParameters = new LinkedList<String>(); try { ParameterMetaData parameterMetaData = prepared.getParameterMetaData(); inputParameters.addAll(Arrays.asList(parameters).subList(0, parameterMetaData.getParameterCount())); } catch (Exception ex) { try { prepared.close(); } catch (SQLException e) { // don't handle } String text = "Error obtaining parameter metadata from prepared statement, consider turning off metadata interrogation via configuration, for statement '" + preparedStatementText + '\''; log.error(text, ex); throw new ExprValidationException(text + ", please check the statement, reason: " + ex.getMessage()); } Map<String, DBOutputTypeDesc> outputProperties; try { outputProperties = compileResultMetaData(prepared.getMetaData(), metadataSetting); } catch (SQLException ex) { try { prepared.close(); } catch (SQLException e) { // don't handle } String text = "Error in statement '" + preparedStatementText + "', failed to obtain result metadata, consider turning off metadata interrogation via configuration"; log.error(text, ex); throw new ExprValidationException(text + ", please check the statement, reason: " + ex.getMessage()); } if (log.isDebugEnabled()) { log.debug(".createDBEventStream in=" + inputParameters.toString() + " out=" + outputProperties.toString()); } // Close statement try { prepared.close(); } catch (SQLException e) { String text = "Error closing prepared statement"; log.error(text, e); throw new ExprValidationException(text + ", reason: " + e.getMessage()); } return new QueryMetaData(inputParameters, outputProperties); }
From source file:ems.util.DataHandler.java
public static boolean updateVoterDetails(String emailId, String mobileNo, String alternatMobileNo, String dob, String age, String community, String gender, String wardNo, String wardSrNo) { String sqlQuery = String.format(Q_U_VOTER_DETAILS, emailId, mobileNo, alternatMobileNo, dob, age, community, gender, wardNo, wardSrNo);//from w w w . j a v a2 s . c o m Connection con = getConnection(); Statement s = null; try { log.info("sqlQuery:" + sqlQuery); s = con.createStatement(); int i = s.executeUpdate(sqlQuery); log.info("updateVoterDetails|" + i); return true; } catch (SQLException e) { log.error("updateVoterDetails: " + e.getMessage()); } finally { try { if (s != null) { s.close(); } if (con != null) { con.close(); } } catch (SQLException ex) { log.error("updateVoterDetails: " + ex.getMessage()); } } return false; }
From source file:ems.util.DataHandler.java
public static String getBoothName(String boothNumber) { String sqlQuery = "select ifnull(booth_no,'') || ' - ' || ifnull(booth_name,'') " + "from booth_master where booth_no=" + boothNumber; Connection con = getConnection(); Statement s = null;//from w w w. j av a 2s .com ResultSet rs = null; try { s = con.createStatement(); rs = s.executeQuery(sqlQuery); while (rs.next()) { return rs.getString(1); } } catch (Exception e) { log.error("getBoothList: " + 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 null; }
From source file:ems.util.DataHandler.java
public static List<MyModel> getWardList() { List<MyModel> myModels = new LinkedList<>(); String sqlQuery = "select distinct ward_no from bmc_history order by 1"; Connection con = getConnection(); Statement s = null;/* w ww . j av a2 s . com*/ ResultSet rs = null; try { s = con.createStatement(); rs = s.executeQuery(sqlQuery); myModels.add(new MyModel("0", "Choose Ward No.")); while (rs.next()) { myModels.add(new MyModel(rs.getString(1), rs.getString(1))); } } catch (Exception e) { log.error("getWardList: " + e.getMessage()); } finally { try { if (rs != null) { rs.close(); } if (s != null) { s.close(); } if (con != null) { con.close(); } } catch (SQLException ex) { log.error("getWardList: " + ex.getMessage()); } } return myModels; }
From source file:ems.util.DataHandler.java
public static List<MyModel> getCommunityList() { List<MyModel> myModels = new LinkedList<>(); String sqlQuery = "select distinct cast_nm from e_details where cast_nm is not null and cast_nm <>'' order by 1"; Connection con = getConnection(); Statement s = null;//from ww w . j a v a 2 s . c o m ResultSet rs = null; try { s = con.createStatement(); rs = s.executeQuery(sqlQuery); myModels.add(new MyModel("0", "Choose Community")); while (rs.next()) { myModels.add(new MyModel(rs.getString(1), rs.getString(1))); } } catch (Exception e) { log.error("getWardList: " + e.getMessage()); } finally { try { if (rs != null) { rs.close(); } if (s != null) { s.close(); } if (con != null) { con.close(); } } catch (SQLException ex) { log.error("getWardList: " + ex.getMessage()); } } return myModels; }
From source file:ems.util.DataHandler.java
public static List<MyModel> getBoothList() { List<MyModel> myModels = new LinkedList<>(); String sqlQuery = "select distinct booth_no, booth_id from booth_master order by 1"; Connection con = getConnection(); Statement s = null;/*from w ww.j a v a 2 s . c o m*/ ResultSet rs = null; try { s = con.createStatement(); rs = s.executeQuery(sqlQuery); myModels.add(new MyModel("0", "Choose Booth No.")); while (rs.next()) { myModels.add(new MyModel(rs.getString(1), rs.getString(2))); } } catch (Exception e) { log.error("getBoothList: " + 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 myModels; }
From source file:ems.util.DataHandler.java
public static MyModel getVoterDetails(String wardNo, String wardSrNo) { String sqlQuery = String.format(Q_S_GET_VOTER, wardNo, wardSrNo); Connection con = getConnection(); Statement s = null;// w w w. j a v a2 s.c o m ResultSet rs = null; try { log.info("sqlQuery:" + sqlQuery); s = con.createStatement(); rs = s.executeQuery(sqlQuery); while (rs.next()) { return new MyModel(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), rs.getString(12), rs.getString(13), rs.getString(14), rs.getString(15), rs.getString(16), rs.getString(17)); } } catch (SQLException e) { log.error("getVoterDetails: " + 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 null; }
From source file:ems.util.DataHandler.java
public static boolean updateVoterStatus(ObservableList<MyModelSimpleStringProperty> list, String status) { String sqlQuery;// w w w .ja v a 2s . co m Connection con = getConnection(); Statement s = null; try { for (MyModelSimpleStringProperty list1 : list) { if (list1.isSelected()) { sqlQuery = String.format(Q_U_VOTER_STATUS, status, list1.getObj1(), list1.getObj2()); log.info("sqlQuery:" + sqlQuery); s = con.createStatement(); int i = s.executeUpdate(sqlQuery); log.info("updateVoterDetails|" + i); } } return true; } catch (SQLException e) { log.error("updateVoterDetails: " + e.getMessage()); } finally { try { if (s != null) { s.close(); } if (con != null) { con.close(); } } catch (SQLException ex) { log.error("updateVoterDetails: " + ex.getMessage()); } } return false; }