List of usage examples for java.sql SQLException toString
public String toString()
From source file:com.intelligentz.appointmentz.controllers.Data.java
public static String equipmentsGetRPI(String hospital_id) { String rpi = ""; try {//from ww w . j a v a 2 s .c o m connection = DBConnection.getDBConnection().getConnection(); String SQL = "select * from rpi natural join room where hospital_id = ?"; preparedStatement = connection.prepareStatement(SQL); preparedStatement.setString(1, hospital_id); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { String auth = resultSet.getString("auth"); String serial = resultSet.getString("serial"); String room_id = resultSet.getString("room_id"); String room_number = resultSet.getString("room_number"); rpi += "<tr><form action='./deleteRPI' method='post'><td>" + auth + "</td><input type='hidden' name='auth' value='" + auth + "'>"; rpi += "<td>" + serial + "</td><input type='hidden' name='serial' value='" + serial + "'><td>" + room_number + "</td><td>" + room_id + "</td>"; rpi += "<input type='hidden' name='room_number' value='" + room_number + "'>"; rpi += "<input type='hidden' name='room_id' value='" + room_id + "'>"; rpi += "<td><button type=\"submit\" onClick=\"return confirm('Do you wish to delete the Device. Ref: Serial = " + serial + ", rel: Room: " + room_number + " ');\" style='color:red'>delete</button></td>"; rpi += "</form>"; rpi += "<form action='./editRPI' method='post'><input type='hidden' name='room_number' value='" + room_number + "'><input type='hidden' name='room_id' value='" + room_id + "'><input type='hidden' name='serial' value='" + serial + "'><input type='hidden' name='auth' value='" + auth + "'>"; rpi += "<td><button type=\"submit\" style='color:blue'>edit</button></td>"; rpi += "</form></tr>"; } } catch (SQLException | IOException | PropertyVetoException e) { //throw new IllegalStateException rpi = "Error"; } finally { try { DbUtils.closeQuietly(resultSet); DbUtils.closeQuietly(preparedStatement); DbUtils.close(connection); } catch (SQLException ex) { Logger.getLogger(register.class.getName()).log(Level.SEVERE, ex.toString(), ex); } } return rpi; }
From source file:com.example.querybuilder.server.Jdbc.java
public static PreparedStatement prepareStatement(Connection connection, String sql) { try {/* www . j av a 2 s. c o m*/ return connection.prepareStatement(sql); } catch (SQLException e) { throw new SqlRuntimeException(e.toString() + "\n" + sql); } }
From source file:com.example.querybuilder.server.Jdbc.java
public static PreparedStatement prepareStatement(Connection connection, String sql, int resultSetType, int resultSetConcurrency) { try {/* w w w .ja va 2s . com*/ return connection.prepareStatement(sql, resultSetType, resultSetConcurrency); } catch (SQLException e) { throw new SqlRuntimeException(e.toString() + "\n" + sql); } }
From source file:com.example.querybuilder.server.Jdbc.java
public static void initializeParameters(PreparedStatement preparedStatement, Object... parameters) { for (int columnOffset = 0, columnNumber = 1; columnOffset < parameters.length; columnOffset++, columnNumber++) { Object value = parameters[columnOffset]; try {/* www. j a v a 2 s . c o m*/ if (value == null) { int parameterType = preparedStatement.getParameterMetaData().getParameterType(columnNumber); preparedStatement.setNull(columnNumber, parameterType); } else { preparedStatement.setObject(columnNumber, value); } } catch (SQLException e) { throw new SqlRuntimeException( e.toString() + "\n" + "columnNumber=" + columnNumber + ", value=" + value); } } }
From source file:com.redhat.rhn.common.db.datasource.test.AdvDataSourceTest.java
private static void forceQuery(Connection c, String query) { try {/* ww w .j a va2s .c o m*/ Statement stmt = c.createStatement(); stmt.execute(query); } catch (SQLException se) { log.warn("Failed to execute query " + query + ": " + se.toString()); } }
From source file:Data.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset./*from w w w . ja va 2 s . com*/ * @throws ClassNotFoundException */ private static XYDataset createDataset(Statement stmt) throws ClassNotFoundException { TimeSeries s1 = new TimeSeries("Humidit"); TimeSeries s2 = new TimeSeries("Temprature"); ResultSet rs = null; try { String sqlRequest = "SELECT * FROM `t_temphum`"; rs = stmt.executeQuery(sqlRequest); Double hum; Double temp; Timestamp date; while (rs.next()) { hum = rs.getDouble("tmp_humidity"); temp = rs.getDouble("tmp_temperature"); date = rs.getTimestamp("tmp_date"); if (tempUnit == "F") { temp = celsiusToFahrenheit(temp.toString()); } if (date != null) { s1.add(new Second(date), hum); s2.add(new Second(date), temp); } else { JOptionPane.showMessageDialog(panelPrincipal, "Il manque une date dans la dase de donne", "Date null", JOptionPane.WARNING_MESSAGE); } } rs.close(); } catch (SQLException e) { String exception = e.toString(); if (e.getErrorCode() == 0) { JOptionPane.showMessageDialog(panelPrincipal, "Le serveur met trop de temps rpondre ! Veuillez rssayer plus tard ou contacter un administrateur", "Connection timed out", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception, "Titre : exception", JOptionPane.ERROR_MESSAGE); // TODO Auto-generated catch block e.printStackTrace(); } } catch (Exception e) { String exception = e.toString(); JOptionPane.showMessageDialog(panelPrincipal, "Voici l'exception : " + exception, "Titre : exception", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); return dataset; }
From source file:org.apache.openjpa.jdbc.sql.DBDictionaryFactory.java
/** * Create the dictionary using the given class name and properties; the * connection may be null if not supplied to the factory. *///from ww w. j a v a2s . co m private static DBDictionary newDBDictionary(JDBCConfiguration conf, String dclass, String props, Connection conn) { DBDictionary dict = null; try { Class<?> c = Class.forName(dclass, true, AccessController.doPrivileged(J2DoPrivHelper.getClassLoaderAction(DBDictionary.class))); dict = (DBDictionary) AccessController.doPrivileged(J2DoPrivHelper.newInstanceAction(c)); } catch (ClassNotFoundException cnfe) { // if the dictionary was not found, make another attempt // at loading the dictionary using the current thread. try { Class<?> c = Thread.currentThread().getContextClassLoader().loadClass(dclass); dict = (DBDictionary) AccessController.doPrivileged(J2DoPrivHelper.newInstanceAction(c)); } catch (Exception e) { if (e instanceof PrivilegedActionException) e = ((PrivilegedActionException) e).getException(); throw new UserException(e).setFatal(true); } } catch (Exception e) { if (e instanceof PrivilegedActionException) e = ((PrivilegedActionException) e).getException(); throw new UserException(e).setFatal(true); } // warn if we could not locate the appropriate dictionary Log log = conf.getLog(JDBCConfiguration.LOG_JDBC); if (log.isWarnEnabled() && dict.getClass() == DBDictionary.class) log.warn(_loc.get("warn-generic")); if (log.isInfoEnabled()) { String infoString = ""; if (conn != null) { try { DatabaseMetaData meta = conn.getMetaData(); infoString = " (" + meta.getDatabaseProductName() + " " + meta.getDatabaseProductVersion() + " ," + meta.getDriverName() + " " + meta.getDriverVersion() + ")"; } catch (SQLException se) { if (log.isTraceEnabled()) log.trace(se.toString(), se); } } log.info(_loc.get("using-dict", dclass, infoString)); } // set the dictionary's metadata Configurations.configureInstance(dict, conf, props, "DBDictionary"); if (conn != null) { try { dict.connectedConfiguration(conn); } catch (SQLException se) { throw new StoreException(se).setFatal(true); } } return dict; }
From source file:org.dspace.app.dav.DAVServlet.java
/** * Pass this request along to the appropriate resource and method. Includes * authentication, where needed. Return true if we handle this request, * false otherwise. True means response has been "sent", false not. * //from w w w .jav a 2s . c o m * @param method the method * @param request the request * @param response the response * * @return true, if service internal * @throws IOException Signals that an I/O exception has occurred. */ protected static boolean serviceInternal(String method, HttpServletRequest request, HttpServletResponse response) throws IOException { // Fake new DAV methods not understood by the Apache Servlet base class // (returns HTTP/500 when it sees unrecognised method) // The way it is faked is by submitting "delete=true" in the PUT URL's // query parameters (for a delete) // The way it is faked is by submitting "mkcol=true" in the PUT URL's // query parameters (for a mk-collection) if (method.equals(METHOD_PUT) && request.getQueryString().indexOf("delete=true") >= 0) { method = METHOD_DELETE; } if (method.equals(METHOD_PUT) && request.getQueryString().indexOf("mkcol=true") >= 0) { method = METHOD_MKCOL; } // if not a DAV method (i.e. POST), defer to superclass. if (!(method.equals(METHOD_PROPFIND) || method.equals(METHOD_PROPPATCH) || method.equals(METHOD_MKCOL) || method.equals(METHOD_COPY) || method.equals(METHOD_MOVE) || method.equals(METHOD_DELETE) || method.equals(METHOD_GET) || method.equals(METHOD_PUT))) { return false; } // set all incoming encoding to UTF-8 request.setCharacterEncoding("UTF-8"); String pathElt[] = getDavResourcePath(request).split("/"); Context context = null; try { // this sends a response on failure, unless it throws. context = authenticate(request, response, null, null); if (context == null) { return true; } // Note: findResource sends error response if it fails. DAVResource resource = DAVResource.findResource(context, request, response, pathElt); if (resource != null) { if (method.equals(METHOD_PROPFIND)) { resource.propfind(); } else if (method.equals(METHOD_PROPPATCH)) { resource.proppatch(); } else if (method.equals(METHOD_COPY)) { resource.copy(); } else if (method.equals(METHOD_DELETE)) { resource.delete(); } else if (method.equals(METHOD_MKCOL)) { resource.mkcol(); } else if (method.equals(METHOD_GET)) { resource.get(); } else if (method.equals(METHOD_PUT)) { resource.put(); } else { response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); } context.complete(); context = null; } } catch (SQLException e) { log.error(e.toString(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, truncateForStatus("Database access error: " + e.toString())); } catch (AuthorizeException e) { if (log.isDebugEnabled()) { log.debug(e.toString(), e); } else { log.info(e.toString()); } response.sendError(HttpServletResponse.SC_FORBIDDEN, truncateForStatus("Access denied: " + e.toString())); } catch (DAVStatusException e) { log.error(e.toString(), e); response.sendError(e.getStatus(), truncateForStatus(e.getMessage())); } catch (IOException e) { log.error(e.toString(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, truncateForStatus("IO Error: " + e.toString())); } catch (Exception e) { log.error(e.toString(), e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, truncateForStatus("IO Error: " + e.toString())); } finally { // Abort the context if it's still valid if (context != null && context.isValid()) { context.abort(); } } return true; }
From source file:com.redhat.rhn.common.hibernate.HibernateFactory.java
/** * utility to convert blob to byte array * @param fromBlob blob to convert// w w w . j a v a 2 s .c om * @return byte array converted from blob */ public static byte[] blobToByteArray(Blob fromBlob) { if (fromBlob == null) { return new byte[0]; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { return toByteArrayImpl(fromBlob, baos); } catch (SQLException e) { LOG.error("SQL Error converting blob to byte array", e); throw new DatabaseException(e.toString()); } catch (IOException e) { LOG.error("I/O Error converting blob to byte array", e); throw new DatabaseException(e.toString()); } finally { try { baos.close(); } catch (IOException ex) { throw new DatabaseException(ex.toString()); } } }
From source file:es.us.mwm.testcloudfoundry.DBClient.java
@Override public void finalize() { try {/* ww w. j a va 2s . c o m*/ conn.close(); } catch (SQLException ex) { log.log(Level.SEVERE, ex.toString(), ex); } }