List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:com.emc.ecs.sync.target.SqlBlobTarget.java
@Override public void filter(SyncObject obj) { if (obj.isDirectory()) { return;/*from ww w . j a v a 2 s . c o m*/ } try (Connection con = dataSource.getConnection(); PreparedStatement ps = con.prepareStatement(insertSql); InputStream in = obj.getInputStream()) { ps.setBinaryStream(1, in, obj.getMetadata().getContentLength()); ps.executeUpdate(); } catch (SQLException e) { throw new RuntimeException("Failed to insert into database: " + e.getMessage(), e); } catch (IOException e) { throw new RuntimeException("Error closing object input stream", e); } }
From source file:com.kumarvv.setl.utils.RowSetUtil.java
/** * get meta columns list with columnId//from ww w.j ava 2 s.c o m * * @param meta * @return */ public Map<String, Integer> getMetaColumns(ResultSetMetaData meta) { final Map<String, Integer> metaColumns = new HashMap<>(); if (meta == null) { return metaColumns; } try { int colCount = meta.getColumnCount(); for (int c = 1; c <= colCount; c++) { metaColumns.put(meta.getColumnName(c), meta.getColumnType(c)); } } catch (SQLException sqle) { Logger.error("error getting metaColumns:", sqle.getMessage()); Logger.trace(sqle); } return metaColumns; }
From source file:com.nextep.designer.sqlgen.model.base.AbstractCapturer.java
@Override public void release(IMutableCaptureContext context) { Connection conn = (Connection) context.getConnectionObject(); try {//from w w w. ja v a 2 s . c o m conn.close(); } catch (SQLException sqle) { LOGGER.warn("Unable to close JDBC connection: " + sqle.getMessage(), sqle); } }
From source file:com.nextep.designer.sqlgen.db2.impl.DB2DatabaseConnector.java
@Override public Connection getConnection(IConnection conn) throws SQLException { final String connURL = getConnectionURL(conn); LOGGER.info("Connecting to DB2 database from URL [" + connURL + "]..."); //$NON-NLS-2$ Connection connection = null; try {/*w w w . j a v a 2s .co m*/ connection = getDriver().connect(connURL, getConnectionInfo(conn)); } catch (SQLException sqle) { LOGGER.error("Unable to connect to DB2 database: " + sqle.getMessage(), sqle); throw sqle; } LOGGER.info("DB2 connection established"); return connection; }
From source file:cz.lbenda.dataman.db.sql.SQLSExecutor.java
private void statementToSQLQueryResult(SQLQueryResult result, Tuple2<PreparedStatement, SQLException> tuple) { if (tuple.get2() != null) { result.setErrorMsg(tuple.get2().getMessage()); LOG.debug(String.format("Problem with execute SQL '%s'", result.getSql()), tuple.get2()); if (consoleShower != null) { consoleShower.accept(this); }// ww w . j av a 2 s . co m } else { try { boolean ex = tuple.get1().execute(); if (ex) { try (ResultSet rs = tuple.get1().getResultSet()) { ResultSetMetaData mtd = rs.getMetaData(); SQLQueryRows sqlRows = new SQLQueryRows(); sqlRows.setSQL(result.getSql()); result.setSqlQueryRows(sqlRows); int columnCount = mtd.getColumnCount(); ColumnDesc columns[] = new ColumnDesc[columnCount]; for (int i = 1; i <= columnCount; i++) { columns[i - 1] = new ColumnDesc(mtd, i, dbConfig.getDialect()); } sqlRows.getMetaData().setColumns(columns); while (rs.next()) { RowDesc row = RowDesc.createNewRow(sqlRows.getMetaData(), RowDesc.RowDescState.LOADED); for (ColumnDesc columnDesc : sqlRows.getMetaData().getColumns()) { row.loadInitialColumnValue(columnDesc, rs); } sqlRows.getRows().add(row); } } } else { result.setAffectedRow(tuple.get1().getUpdateCount()); } } catch (SQLException e) { result.setErrorMsg(e.getMessage()); LOG.debug(String.format("Problem with execute SQL '%s'", result.getSql()), e); } } }
From source file:DedicatedConnectionServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>A Dedicated Connection</title>"); out.println("</head>"); out.println("<body>"); Statement statement = null;//from w ww. j av a 2 s . c om ResultSet resultSet = null; String userName = null; try { // test the connection statement = connection.createStatement(); resultSet = statement.executeQuery("select initcap(user) from sys.dual"); if (resultSet.next()) userName = resultSet.getString(1); } catch (SQLException e) { out.println("DedicatedConnection.doGet() SQLException: " + e.getMessage() + "<p>"); } finally { if (resultSet != null) try { resultSet.close(); } catch (SQLException ignore) { } if (statement != null) try { statement.close(); } catch (SQLException ignore) { } } out.println("Hello " + userName + "!<p>"); out.println("This Servlet's database connection was created on " + new java.util.Date(connected) + "<p>"); out.println("</body>"); out.println("</html>"); }
From source file:com.nextep.designer.sqlgen.oracle.impl.OracleDatabaseConnector.java
@Override public Connection getConnection(IConnection conn) throws SQLException { LOGGER.info(MessageFormat.format(OracleMessages.getString("connecting"), conn)); //$NON-NLS-1$ Connection connection = null; try {//from w w w . j a v a2s . c om connection = getDriver().connect(getConnectionURL(conn), getConnectionInfo(conn)); } catch (SQLException sqle) { LOGGER.error("Unable to connect to Oracle database: " + sqle.getMessage(), sqle); throw sqle; } LOGGER.info(OracleMessages.getString("connectionEstablished")); //$NON-NLS-1$ return connection; }
From source file:com.qwazr.connectors.DatabaseConnector.java
@Override public void close() { if (basicDataSource != null) { try {/*from w w w . j ava 2 s .c om*/ if (!basicDataSource.isClosed()) basicDataSource.close(); } catch (SQLException e) { logger.error(e.getMessage(), e); } } }
From source file:fll.web.developer.QueryHandler.java
@SuppressFBWarnings(value = { "SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE" }, justification = "Executing query from user") @Override//from w w w. ja v a2s.com protected void processRequest(final HttpServletRequest request, final HttpServletResponse response, final ServletContext application, final HttpSession session) throws IOException, ServletException { final List<String> columnNames = new LinkedList<String>(); final List<Map<String, String>> data = new LinkedList<Map<String, String>>(); String error = null; DataSource datasource = ApplicationAttributes.getDataSource(application); Statement stmt = null; ResultSet rs = null; Connection connection = null; try { connection = datasource.getConnection(); final String query = request.getParameter(QUERY_PARAMETER); stmt = connection.createStatement(); rs = stmt.executeQuery(query); ResultSetMetaData meta = rs.getMetaData(); for (int columnNum = 1; columnNum <= meta.getColumnCount(); ++columnNum) { columnNames.add(meta.getColumnName(columnNum).toLowerCase()); } while (rs.next()) { final Map<String, String> row = new HashMap<String, String>(); for (final String columnName : columnNames) { final String value = rs.getString(columnName); row.put(columnName, value); } data.add(row); } } catch (final SQLException e) { error = e.getMessage(); LOGGER.error("Exception doing developer query", e); } finally { SQLFunctions.close(rs); SQLFunctions.close(stmt); SQLFunctions.close(connection); } response.setContentType("application/json"); response.setCharacterEncoding(Utilities.DEFAULT_CHARSET.name()); final ResultData result = new ResultData(columnNames, data, error); final ObjectMapper jsonMapper = new ObjectMapper(); final Writer writer = response.getWriter(); jsonMapper.writeValue(writer, result); }
From source file:TestAppletPolicy.java
public void init() { System.out.println(getParameter("otherparams")); try {/*from w w w .j a v a 2 s . com*/ System.out.println("init(): loading OracleDriver for applet created at " + created.toString()); DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); System.out.println("init(): getting connection"); conn = DriverManager.getConnection("jdbc:oracle:thin:@dssnt01:1521:dssora01", "scott", "tiger"); } catch (SQLException e) { System.err.println("init(): SQLException: " + e.getMessage()); } }