List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:com.jfinal.plugin.activerecord.Config.java
public final void close(Statement st, Connection conn) { if (st != null) { try {//from www. ja v a2 s . c om st.close(); } catch (SQLException e) { LogKit.error(e.getMessage(), e); } } if (threadLocal.get() == null) { // in transaction if conn in threadlocal if (conn != null) { try { conn.close(); } catch (SQLException e) { throw new ActiveRecordException(e); } } } }
From source file:Database.Handler.java
public int deleteQuery(String sql, String[] para) { PreparedStatement ps;// w w w . j av a 2s . c om int res = -1; //return result try { Connection c = DriverManager.getConnection(DbConfig.connectionString, DbConfig.dbUserName, DbConfig.dbPassword); ps = c.prepareStatement(sql); for (int i = 0; i < para.length; i++) { ps.setString(i + 1, para[i]); } int result = ps.executeUpdate(); res = (result != 0) ? 1 : -1; System.out.println("result = " + result); return res; } catch (SQLException ex) { System.out.printf("Handler updateQuery error:" + ex.getMessage()); return res; } }
From source file:mobi.nordpos.catalog.action.ProductCreateActionBean.java
@ValidationMethod(priority = 1) public void validateProductReferency(ValidationErrors errors) { try {/*www . j a v a 2 s. c o m*/ String plu = getPLU(getProduct().getProductCategory().getCode()); String code = getShortCode(); getProduct().setReference(plu.concat("-").concat(code)); } catch (SQLException ex) { getContext().getValidationErrors().addGlobalError(new SimpleError(ex.getMessage())); } }
From source file:org.elasticsearch.xpack.qa.sql.jdbc.ErrorsTestCase.java
@Override public void testSelectFromMissingIndex() throws SQLException { try (Connection c = esJdbc()) { SQLException e = expectThrows(SQLException.class, () -> c.prepareStatement("SELECT * FROM test").executeQuery()); assertEquals("Found 1 problem(s)\nline 1:15: Unknown index [test]", e.getMessage()); }//from ww w . j av a2 s .co m }
From source file:classes.Product.java
@Override protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws IOException { Set<String> keySet = request.getParameterMap().keySet(); try (PrintWriter printer = response.getWriter()) { Connection connection = connect(); if (keySet.contains("productId")) { PreparedStatement pStatement; String query = "" + "delete FROM products where Product_id=" + request.getParameter("productId"); pStatement = connection.prepareStatement(query); try { pStatement.executeUpdate(); } catch (SQLException ex) { System.out.println("SQL Exception " + ex.getMessage()); }// ww w . j av a2s .com } else { printer.println("No dta found"); } } catch (SQLException ex) { System.err.println("SQL Exception Error: " + ex.getMessage()); } }
From source file:Database.Handler.java
public int updateQuery(String sql, String[] para) { PreparedStatement ps;//from w w w.j a va 2 s .c o m int res = -1; //return result try { Connection c = DriverManager.getConnection(DbConfig.connectionString, DbConfig.dbUserName, DbConfig.dbPassword); ps = c.prepareStatement(sql); System.out.println(ps.toString()); for (int i = 0; i < para.length; i++) { ps.setString(i + 1, para[i]); } System.out.println(ps.toString()); int result = ps.executeUpdate(); res = (result != 0) ? 1 : -1; return res; } catch (SQLException ex) { System.out.println("Handler updateQuery error:" + ex.getMessage()); return res; } }
From source file:uk.org.rbc1b.roms.controller.report.ReportsController.java
/** * Run a fixed report, returning the data in a downloadable csv format. * @param reportId report id//from w w w. j a v a 2s.com * @param response servlet response to output the csv data to directly * @throws IOException on failure to write to output stream */ @RequestMapping(value = "fixed/{reportId}/csv", method = RequestMethod.GET) @PreAuthorize("hasPermission('REPORT', 'READ')") public void downloadCsvReport(@PathVariable Integer reportId, HttpServletResponse response) throws IOException { FixedReport fixedReport = reportDao.findFixedReport(reportId); if (fixedReport == null) { throw new ResourceNotFoundException("No fixed report #" + reportId); } ReportResults reportResults; try { reportResults = extractResults(fixedReport.getQuery()); } catch (SQLException e) { throw new IllegalStateException("Failed to extract report data. Message: [" + e.getMessage() + "]", e); } String[] headers = reportResults.columnNames.toArray(new String[reportResults.columnNames.size()]); List<String[]> records = new ArrayList<String[]>(); for (List<String> reportRow : reportResults.resultRows) { records.add(reportRow.toArray(new String[reportRow.size()])); } String fileName = "edifice-report-" + fixedReport.getName().replace(" ", "-").toLowerCase() + ".csv"; response.setContentType(MediaType.CSV_UTF_8.toString()); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); OutputStream output = response.getOutputStream(); CSVWriter writer = new CSVWriter(new OutputStreamWriter(output), '\u0009'); writer.writeNext(headers); writer.writeAll(records); writer.close(); }
From source file:com.evolveum.midpoint.tools.ninja.ImportDDL.java
private void readScript(File script, BufferedReader reader, Connection connection) throws IOException { System.out.println("Reading DDL script file '" + script.getAbsolutePath() + "'."); reader = new BufferedReader(new InputStreamReader(new FileInputStream(script), "utf-8")); StringBuilder query = new StringBuilder(); String line;//from w ww .j a va2s . co m while ((line = reader.readLine()) != null) { //skip comments if (line.length() == 0 || line.length() > 0 && line.charAt(0) == '-') { continue; } if (query.length() != 0) { query.append(' '); } query.append(line.trim()); //If one command complete if (query.charAt(query.length() - 1) == ';') { query.deleteCharAt(query.length() - 1); try { String queryStr = query.toString(); System.out.println("Executing query: " + queryStr); Statement stmt = connection.createStatement(); stmt.execute(queryStr); stmt.close(); } catch (SQLException ex) { System.out.println("Exception occurred during SQL statement '" + query.toString() + "' execute, reason: " + ex.getMessage()); } query = new StringBuilder(); } } }
From source file:Database.Handler.java
public List<T> searchQuery(String sql, String[] para, Class outputClass) { System.out.println(sql);/* w w w . j a v a2 s.c om*/ List<T> list; PreparedStatement ps; try { Connection c = DriverManager.getConnection(DbConfig.connectionString, DbConfig.dbUserName, DbConfig.dbPassword); ps = c.prepareStatement(sql); for (int i = 0; i < para.length; i++) { ps.setString(i + 1, para[i]); } //System.out.println(ps.toString()); ResultSet rs = ps.executeQuery(); list = mapRersultSetToObject(rs, outputClass); ps.close(); c.close(); return list; } catch (SQLException e) { System.out.println("Handler searchQuery error:" + e.getMessage()); return null; } }
From source file:Database.Handler.java
public int insertQuery(String sql, String[] para, Class outputClass) { PreparedStatement ps;// w w w .j a va 2 s .c o m try { Connection c = DriverManager.getConnection(DbConfig.connectionString, DbConfig.dbUserName, DbConfig.dbPassword); ps = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); for (int i = 0; i < para.length; i++) { ps.setString(i + 1, para[i]); } System.out.println(ps); ps.executeUpdate(); ResultSet rs = ps.getGeneratedKeys(); if (rs.next()) { return rs.getInt(1); } return -1; } catch (SQLException ex) { System.out.println("Handler insertQuery error:" + ex.getMessage()); return -1; } }