List of usage examples for java.sql SQLException toString
public String toString()
From source file:com.poscoict.license.web.controller.ExceptionControllerAdvice.java
@ExceptionHandler(SQLException.class) public ModelAndView handleSQLException(SQLException ex) { logger.error(ex.toString()); ModelAndView mv = new ModelAndView(DEFAULT_ERROR_VIEW); mv.addObject("name", ex.getClass().getSimpleName()); mv.addObject("message", "?? ? . ? ."); return mv;/*www.j a va2s .c o m*/ }
From source file:org.apache.hadoop.sqoop.manager.MySQLManager.java
@Override public String[] listDatabases() { // TODO(aaron): Add an automated unit test for this. ResultSet results = execute("SHOW DATABASES"); if (null == results) { return null; }/*from w ww. ja va 2 s. com*/ try { ArrayList<String> databases = new ArrayList<String>(); while (results.next()) { String dbName = results.getString(1); databases.add(dbName); } return databases.toArray(new String[0]); } catch (SQLException sqlException) { LOG.error("Error reading from database: " + sqlException.toString()); return null; } }
From source file:net.kados.gtp.app.libs.Teryt.Subjects.Streets.java
protected void save() { try {//ww w. j a va 2 s.com this.street.fillTable(streets); streets.clear(); } catch (SQLException ex) { parserMessages.sendMessage(ex.toString()); } }
From source file:eionet.gdem.qa.WQCheckerJob.java
@Override public void execute(final JobExecutionContext context) throws JobExecutionException { LOGGER.debug("RUN WQChecker."); // get new received jobs from the DB String[] newJobs = null;/*from w ww . ja v a 2 s . c o m*/ try { int activeJobs = xqJobDao.countActiveJobs(); if (activeJobs >= Properties.wqMaxJobs) { LOGGER.debug( "The number of active jobs is greater or equal than max jobs allowed to run in parallel: active jobs:" + activeJobs + "; max jobs: " + Properties.wqMaxJobs); } else { newJobs = xqJobDao.getJobsLimit(Constants.XQ_RECEIVED, Properties.wqMaxJobs - activeJobs); } } catch (SQLException sqe) { LOGGER.fatal("*** SQL error getting jobs from DB: " + sqe.toString()); } catch (Exception e) { LOGGER.error("*** error when getting received jobs: " + e.toString()); } XQueryTask xq; if (newJobs != null) { for (int i = 0; i < newJobs.length; i++) { LOGGER.debug("*** waiting job: " + newJobs[i]); xq = new XQueryTask(newJobs[i]); WQExecutor.getInstance().execute(xq); } } }
From source file:org.starfishrespect.myconsumption.android.tasks.SensorValuesUpdater.java
public void refreshDB() { AsyncTask<Void, List, Void> task = new AsyncTask<Void, List, Void>() { @Override// www .ja v a 2 s . co m protected Void doInBackground(Void... params) { DatabaseHelper db = SingleInstance.getDatabaseHelper(); RestTemplate template = new RestTemplate(); HttpHeaders httpHeaders = CryptoUtils.createHeadersCurrentUser(); ResponseEntity<List> responseEnt; template.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); try { SensorValuesDao valuesDao = new SensorValuesDao(db); for (SensorData sensor : db.getSensorDao().queryForAll()) { int startTime = (int) (sensor.getLastLocalValue().getTime() / 1000); String url = String.format(SingleInstance.getServerUrl() + "sensors/%s/data?start=%d", sensor.getSensorId(), startTime); Log.d(TAG, url); responseEnt = template.exchange(url, HttpMethod.GET, new HttpEntity<>(httpHeaders), List.class); List<List<Integer>> sensorData = responseEnt.getBody(); List<SensorValue> values = new ArrayList<>(); long last = 0; long first = Long.MAX_VALUE; for (List<Integer> value : sensorData) { values.add(new SensorValue(value.get(0), value.get(1))); if (value.get(0) > last) { last = value.get(0); } if (value.get(0) < first) { first = value.get(0); } } valuesDao.insertSensorValues(sensor.getSensorId(), values); sensor.setLastLocalValue(new Date(last * 1000)); long formerFirst = sensor.getFirstLocalValue().getTime() / 1000; if (formerFirst > first || formerFirst == 0) { sensor.setFirstLocalValue(new Date(first * 1000)); } db.getSensorDao().update(sensor); Log.d(TAG, "Inserted values to " + last); } } catch (SQLException e) { Log.e(TAG, "Error:" + e.toString()); } return null; } @Override protected void onPostExecute(Void aVoid) { if (updateFinishedCallback != null) { updateFinishedCallback.onUpdateFinished(); } } }; task.execute(); }
From source file:org.apache.hadoop.sqoop.orm.TestClassWriter.java
@Before public void setUp() { testServer = new HsqldbTestServer(); try {/*from ww w. j av a 2 s . c o m*/ testServer.resetServer(); } catch (SQLException sqlE) { LOG.error("Got SQLException: " + sqlE.toString()); fail("Got SQLException: " + sqlE.toString()); } catch (ClassNotFoundException cnfe) { LOG.error("Could not find class for db driver: " + cnfe.toString()); fail("Could not find class for db driver: " + cnfe.toString()); } manager = testServer.getManager(); options = testServer.getImportOptions(); }
From source file:org.accada.epcis.repository.capture.CaptureOperationsSession.java
public void close() throws SQLException { for (PreparedStatement ps : inserts.values()) { try {//from ww w. java2s .co m ps.close(); } catch (SQLException e) { LOG.warn("Error closing PreparedStatement: " + e.toString() + ". Will continue ... "); } } for (PreparedStatement ps : batchInserts.values()) { try { ps.close(); } catch (SQLException e) { LOG.warn("Error closing PreparedStatement: " + e.toString() + ". Will continue ... "); } } for (PreparedStatement ps : selects.values()) { try { ps.close(); } catch (SQLException e) { LOG.warn("Error closing PreparedStatement: " + e.toString() + ". Will continue ... "); } } connection.close(); }
From source file:com.oracle.tutorial.jdbc.CoffeesTableModel.java
/** Method from interface TableModel; returns the column name at columnIndex * based on information from ResultSetMetaData *///from www.ja v a 2 s . c om public String getColumnName(int column) { try { return this.metadata.getColumnLabel(column + 1); } catch (SQLException e) { return e.toString(); } }
From source file:AllEmployeesServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head><title>All Employees</title></head>"); out.println("<body>"); out.println("<center><h1>All Employees</h1>"); Connection conn = null;//from w w w . j a v a 2s. c om Statement stmt = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:Employees"); stmt = conn.createStatement(); String orderBy = request.getParameter("sort"); if ((orderBy == null) || orderBy.equals("")) { orderBy = "SSN"; } String orderByDir = request.getParameter("sortdir"); if ((orderByDir == null) || orderByDir.equals("")) { orderByDir = "asc"; } String query = "SELECT Employees.SSN, Employees.Name, " + "Employees.Salary, " + "Employees.Hiredate, Location.Location " + "FROM Location " + "INNER JOIN Employees " + "ON Location.Loc_Id = Employees.Loc_Id " + "ORDER BY " + orderBy + " " + orderByDir + ";"; ResultSet rs = stmt.executeQuery(query); while (rs.next()) { long employeeSSN = rs.getLong("SSN"); String employeeName = rs.getString("Name"); long employeeSalary = rs.getLong("Salary"); Date employeeHiredate = rs.getDate("Hiredate"); String employeeLocation = rs.getString("Location"); out.print(employeeSSN + "::"); out.print(employeeName + "::"); out.print(employeeSalary + "::"); out.print(employeeHiredate + "::"); out.print(employeeLocation + "::"); } } catch (SQLException e) { out.println("An error occured while retrieving " + "all employees: " + e.toString()); } catch (ClassNotFoundException e) { throw (new ServletException(e.toString())); } finally { try { if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (SQLException ex) { } } out.println("</center>"); out.println("</body>"); out.println("</html>"); out.close(); }
From source file:com.oracle.tutorial.jdbc.CoffeesTableModel.java
/** Method from interface TableModel; returns the value for the cell specified * by columnIndex and rowIndex. TableModel uses this method to populate * itself with data from the row set. SQL starts numbering its rows and * columns at 1, but TableModel starts at 0. *///from w w w. j av a 2s . c o m public Object getValueAt(int rowIndex, int columnIndex) { try { this.coffeesRowSet.absolute(rowIndex + 1); Object o = this.coffeesRowSet.getObject(columnIndex + 1); if (o == null) return null; else return o.toString(); } catch (SQLException e) { return e.toString(); } }