List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:com.espertech.esper.epl.db.ConnectionCache.java
/** * Make a new pair of resources.//from ww w.j a va 2s . co m * @return pair of resources */ protected Pair<Connection, PreparedStatement> makeNew() { log.info(".makeNew Obtaining new connection and statement"); Connection connection; try { connection = databaseConnectionFactory.getConnection(); } catch (DatabaseConfigException ex) { throw new EPException("Error obtaining connection", ex); } PreparedStatement preparedStatement; try { preparedStatement = connection.prepareStatement(sql); } catch (SQLException ex) { try { connection.close(); } catch (SQLException e) { log.warn("Error closing connection: " + e.getMessage(), e); } throw new EPException("Error preparing statement '" + sql + '\'', ex); } return new Pair<Connection, PreparedStatement>(connection, preparedStatement); }
From source file:br.com.great.dao.JogosDAO.java
/** * Retorna um jogo com todos os seus dados * @return JSONArray lista de todos os jogos *//*from www . j av a 2s. c om*/ public Jogo getJogo(int jogo_id) { PreparedStatement pstmt = null; ResultSet rs = null; Connection conexao = criarConexao(); try { String sql = "select * from jogos where id=" + jogo_id; pstmt = conexao.prepareStatement(sql); rs = pstmt.executeQuery(); while (rs.next()) { Jogo jogo = new Jogo(); jogo.setId(rs.getInt("id")); jogo.setNome(rs.getString("nome")); jogo.setIcone(rs.getString("icone")); jogo.setPosicao(new Posicao(rs.getDouble("latitude"), rs.getDouble("longitude"))); jogo.setNomeficticio(rs.getString("nomeficticio")); jogo.setStatus(rs.getInt("status")); return jogo; } } catch (SQLException e) { System.out.println("Erro no getJogo: " + e.getMessage()); } finally { fecharConexao(conexao, pstmt, rs); } return null; }
From source file:com.nextep.designer.sqlgen.postgre.impl.PostgreSqlDatabaseConnector.java
@Override public void doPostConnectionSettings(IConnection conn, Connection sqlConn) throws SQLException { final String schema = conn.getSchema(); if (schema != null && !"".equals(schema.trim())) { //$NON-NLS-1$ Statement stmt = null;/*from w w w . jav a 2s. c o m*/ try { stmt = sqlConn.createStatement(); stmt.execute("SET search_path TO " + schema + ",public"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (SQLException sqle) { LOGGER.error("Unable to set the search_path variable: " + sqle.getMessage(), sqle); throw sqle; } finally { CaptureHelper.safeClose(null, stmt); } } }
From source file:net.firejack.platform.core.utils.OpenFlameDataSource.java
/** * Creates a JDBC connection factory for this datasource. This method only * exists so subclasses can replace the implementation class. *///from w w w . j ava 2 s. c o m protected ConnectionFactory createConnectionFactory() throws SQLException { try { return super.createConnectionFactory(); } catch (SQLException e) { logger.error(e.getMessage()); throw new UnsupportedOperationException(e); } }
From source file:xyz.vopen.passport.commons.jdbc.JdbcTemplate.java
public int[] batch(String sql, Object[][] params) { Connection conn = null;/*from w w w . ja v a 2 s .c o m*/ try { conn = getConnection(); // logger.info("dbutils.batch??"); return queryRunner.batch(conn, sql, params); } catch (SQLException t) { System.out.println(t.getMessage()); throw new DataIntegrityViolationException(t.getMessage()); } finally { DataSourceUtils.releaseConnection(conn, this.getDataSource()); // logger.info("dbutils.batch?"); } }
From source file:com.emc.vipr.sync.target.SqlBlobTarget.java
@Override public void filter(SyncObject obj) { if (obj.isDirectory()) { return;//from ww w .j av 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().getSize()); ps.executeUpdate(); } catch (SQLException e) { throw new RuntimeException("Failed to insert into database: " + e.getMessage(), e); } catch (IOException e) { throw new RuntimeException("Failed to stream object data: " + e.getMessage(), e); } }
From source file:jp.primecloud.auto.tool.management.zabbix.ZabbixSqlService.java
public void createUsergroup(String userid, String username) throws SQLException, Exception { try {/*from w ww . j a v a2 s. c o m*/ String sql1 = "update ids set nextid=nextid+1 where nodeid=0 and table_name='usrgrp' and field_name ='usrgrpid'"; sqlExecuter.execute(sql1); String sql2 = "select nextid from ids where nodeid=0 and table_name='usrgrp' and field_name ='usrgrpid'"; int usrgrpid = sqlExecuter.getNextid(sql2); String sql3 = "insert into usrgrp (usrgrpid, name, gui_access, users_status, api_access, debug_mode) values (" + usrgrpid + ", '" + username + "', 0, 0, 0, 0)"; sqlExecuter.execute(sql3); String sql4 = "update ids set nextid=nextid+1 where nodeid=0 and table_name='users_groups' and field_name ='id'"; sqlExecuter.execute(sql4); String sql5 = "select nextid from ids where nodeid=0 and table_name='users_groups' and field_name ='id'"; int id = sqlExecuter.getNextid(sql5); String sql6 = "insert into users_groups (id,usrgrpid,userid) values (" + id + "," + usrgrpid + "," + userid + ")"; sqlExecuter.execute(sql6); String sql7 = "select groupid from groups where name ='" + username + "'"; int groupid = sqlExecuter.getGroupid(sql7); String sql8 = "update ids set nextid=nextid+1 where nodeid=0 and table_name='rights' and field_name ='rightid'"; sqlExecuter.execute(sql8); String sql9 = "select nextid from ids where nodeid=0 and table_name='rights' and field_name ='rightid'"; int rightid = sqlExecuter.getNextid(sql9); //groupid?usrgrp?usrgrpid //ID?groups?groupid String sql10 = "insert into rights (rightid,groupid,permission,id) values (" + rightid + ", " + usrgrpid + ", 2, " + groupid + ")"; sqlExecuter.execute(sql10); } catch (SQLException e) { log.error(e.getMessage(), e); throw new SQLException(e); } catch (Exception e) { log.error(e.getMessage(), e); throw new Exception(e); } }
From source file:edu.pitt.resumecore.Symptom.java
private void loadSymptom(String symptomID) { String sql = "SELECT * FROM emr.symptoms WHERE symptomID = '" + symptomID + "'"; try {// w w w. ja va2 s. c om ResultSet rs = db.getResultSet(sql); if (rs.next()) { this.symptomID = rs.getString("symptomID"); this.symptomName = rs.getString("symptomName"); } } catch (SQLException ex) { ErrorLogger.log("An error had occured in loadSymptom() method of Symptom class. " + ex.getMessage()); ErrorLogger.log(sql); } }
From source file:com.kumarvv.setl.utils.RowSetUtil.java
/** * get meta columns/*from ww w . ja v a 2 s . com*/ * * @param jrs * @return */ public Map<String, Integer> getMetaColumns(JdbcRowSet jrs) { if (jrs == null) { return new HashMap<>(); } try { return getMetaColumns(jrs.getMetaData()); } catch (SQLException sqle) { Logger.error("error getting metaColumns:", sqle.getMessage()); Logger.trace(sqle); return new HashMap<>(); } }
From source file:com.nextep.designer.sqlgen.sqlite.impl.SQLLiteDatabaseConnector.java
@Override public Connection getConnection(IConnection conn) throws SQLException { final String connURL = getConnectionURL(conn); LOGGER.info(MessageFormat.format(SQLiteMessages.getString("connector.sqlite.connecting"), //$NON-NLS-1$ connURL));//from w w w. j a va2 s .c o m Connection connection = null; try { DriverManager.setLoginTimeout(15); connection = DriverManager.getConnection(connURL, conn.getLogin(), conn.getPassword()); } catch (SQLException sqle) { LOGGER.error("Unable to connect to SQLite database: " + sqle.getMessage(), sqle); throw sqle; } LOGGER.info("SQLite connection established"); return connection; }