List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:be.ugent.tiwi.sleroux.newsrec.stormNewsFetch.dao.mysqlImpl.JDBCRatingsDao.java
/** * * @throws RatingsDaoException/*w ww. j av a2 s. co m*/ */ public JDBCRatingsDao() throws RatingsDaoException { logger.debug("constructor called"); if (connectionPool == null) { try { logger.debug("creating connectionpool"); String driver = bundle.getString("dbDriver"); String user = bundle.getString("dbUser"); String pass = bundle.getString("dbPass"); String url = bundle.getString("dbUrl"); url = url + "?user=" + user + "&password=" + pass; connectionPool = new BasicDataSource(); connectionPool.setDriverClassName(driver); connectionPool.setUsername(user); connectionPool.setPassword(pass); connectionPool.setUrl(url); logger.debug("connectionpool created"); logger.debug("creating preparedstatements"); String statementText = bundle.getString("selectRatingsQuery"); Connection conn = connectionPool.getConnection(); conn.setAutoCommit(true); selectStatement = conn.prepareStatement(statementText); statementText = bundle.getString("insertUpdateRatingsQuery"); insertUpdateRatingStatement = conn.prepareStatement(statementText); logger.debug("created preparedstatements"); } catch (SQLException ex) { logger.error(ex.getMessage(), ex); throw new RatingsDaoException(ex); } } }
From source file:Accounts.java
private void displaySQLErrors(SQLException e) { errorText.append("SQLException: " + e.getMessage() + "\n"); errorText.append("SQLState: " + e.getSQLState() + "\n"); errorText.append("VendorError: " + e.getErrorCode() + "\n"); }
From source file:org.owasp.webgoat.plugin.introduction.SqlInjectionLesson5a.java
protected AttackResult injectableQuery(String accountName) { try {//from w ww .j a va 2 s. c o m Connection connection = DatabaseUtilities.getConnection(getWebSession()); String query = "SELECT * FROM user_data WHERE last_name = '" + accountName + "'"; try { Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet results = statement.executeQuery(query); if ((results != null) && (results.first())) { ResultSetMetaData resultsMetaData = results.getMetaData(); StringBuffer output = new StringBuffer(); output.append(writeTable(results, resultsMetaData)); results.last(); // If they get back more than one user they succeeded if (results.getRow() >= 6) { return trackProgress(success().feedback("sql-injection.5a.success") .feedbackArgs(output.toString()).build()); } else { return trackProgress(failed().output(output.toString()).build()); } } else { return trackProgress(failed().feedback("sql-injection.5a.no.results").build()); } } catch (SQLException sqle) { return trackProgress(failed().output(sqle.getMessage()).build()); } } catch (Exception e) { return trackProgress(failed().output(this.getClass().getName() + " : " + e.getMessage()).build()); } }
From source file:TestAppletPolicy.java
public void paint(Graphics g) { System.out.println("paint(): querying the database"); try {//from w w w .j a v a 2 s . co m Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery("select 'Hello '||initcap(USER) result from dual"); while (rset.next()) g.drawString(rset.getString(1), 10, 10); rset.close(); stmt.close(); } catch (SQLException e) { System.err.println("paint(): SQLException: " + e.getMessage()); } }
From source file:be.ugent.tiwi.sleroux.newsrec.stormNewsFetch.dao.mysqlImpl.JDBCViewsDao.java
/** * * @throws ViewsDaoException/* w w w . j av a 2 s.c o m*/ */ public JDBCViewsDao() throws ViewsDaoException { logger.debug("JDBCViewsDao constructor called"); if (connectionPool == null) { logger.debug("creating connectionpool"); String driver = bundle.getString("dbDriver"); String user = bundle.getString("dbUser"); String pass = bundle.getString("dbPass"); String url = bundle.getString("dbUrl"); url = url + "?user=" + user + "&password=" + pass; connectionPool = new BasicDataSource(); connectionPool.setDriverClassName(driver); connectionPool.setUsername(user); connectionPool.setPassword(pass); connectionPool.setUrl(url); logger.debug("connectionpool created"); } try { logger.debug("creating preparedstatements"); String statementText = bundle.getString("selectViewsQuery"); selectStatement = connectionPool.getConnection().prepareStatement(statementText); statementText = bundle.getString("insertUpdateViewsQuery"); insertViewsStatement = connectionPool.getConnection().prepareStatement(statementText); statementText = bundle.getString("selectTopNViewsQuery"); selectTopNStatement = connectionPool.getConnection().prepareStatement(statementText); logger.debug("created preparedstatements"); } catch (SQLException ex) { logger.error(ex.getMessage(), ex); throw new ViewsDaoException(ex); } }
From source file:br.com.great.dao.SonsDAO.java
/** * * Mtodo responsvel por get os dados da CSons no banco de dados * * @author Carleandro Noleto/*from w w w.ja va2 s . c om*/ * @param mecanica_id int * @return JSONObject Dados CSons * @since 14/01/2015 * @version 1.0 */ public Som getMecCSons(int mecanica_id) { PreparedStatement pstmt = null; ResultSet rs = null; Connection conexao = criarConexao(); Som cSons = null; try { String sql = "SELECT * FROM `csons` WHERE `csons`.`mecsimples_id` = " + mecanica_id; pstmt = conexao.prepareStatement(sql); rs = pstmt.executeQuery(); if (rs.next()) { cSons = new Som(); cSons.setSom_id(rs.getInt("id")); cSons.setArqSom(rs.getString("som")); cSons.setCapturarObjeto(new CapturarObjeto()); cSons.getCapturarObjeto().setJogador_id(rs.getInt("jogador_id")); cSons.getCapturarObjeto() .setPosicao(new Posicao(rs.getDouble("latitude"), rs.getDouble("longitude"))); cSons.setMecsimples_id(rs.getInt("mecsimples_id")); } } catch (SQLException e) { System.out.println("Erro ao listar dados de uma mecanica csons: " + e.getMessage()); } finally { fecharConexao(conexao, pstmt, rs); } return cSons; }
From source file:com.flexive.core.storage.PostgreSQL.PostgreSQLHierarchicalStorage.java
/** * {@inheritDoc}/*from www. j a v a 2s .co m*/ */ @Override public void lockTables(Connection con, long id, int version) throws FxRuntimeException { try { PreparedStatement ps = null; try { String ver = version <= 0 ? "" : " AND VER=?"; ps = con.prepareStatement( "SELECT * FROM " + DatabaseConst.TBL_CONTENT + " WHERE ID=?" + ver + " FOR UPDATE"); ps.setLong(1, id); if (version > 0) ps.setInt(2, version); ps.executeQuery(); ps.close(); ps = con.prepareStatement( "SELECT * FROM " + DatabaseConst.TBL_CONTENT_DATA + " WHERE ID=?" + ver + " FOR UPDATE"); ps.setLong(1, id); if (version > 0) ps.setInt(2, version); ps.executeQuery(); ps.close(); /*ps = con.prepareStatement("SELECT * FROM " + DatabaseConst.TBL_CONTENT_BINARY + " WHERE ID=?" + ver + " FOR UPDATE"); ps.setLong(1, id); if (version > 0) ps.setInt(2, version); ps.executeQuery();*/ //fulltext table uses MyISAM engine and can not be locked } finally { if (ps != null) ps.close(); } if (LOG.isDebugEnabled()) LOG.debug("Locked instances of id #" + id + (version > 0 ? " and version #" + version : " (all versions)")); } catch (SQLException e) { throw new FxDbException(LOG, e, "ex.db.sqlError", e.getMessage()).asRuntimeException(); } }
From source file:com.nextep.designer.sqlgen.db2.impl.DB2DatabaseConnector.java
@Override public void doPostConnectionSettings(IConnection conn, Connection sqlConn) throws SQLException { final String schema = conn.getSchema(); /*/* www . j a v a2 s . com*/ * If schema is set to a non-empty value, we set the first value of the CURRENT PATH with * the specified schema. We don't need to set the CURRENT SCHEMA variable as it is already * set with the connection properties. */ if (schema != null && !"".equals(schema.trim())) { //$NON-NLS-1$ Statement stmt = null; try { stmt = sqlConn.createStatement(); stmt.execute("SET CURRENT PATH " + schema + ", CURRENT PATH"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (SQLException sqle) { LOGGER.error("Unable to set the DB2 current path: " + sqle.getMessage(), sqle); throw sqle; } finally { CaptureHelper.safeClose(null, stmt); } } }
From source file:br.com.great.dao.VideosDAO.java
/** * * Mtodo responsvel por get os dados da CSons no banco de dados * * @author Carleandro Noleto/*w w w .j a v a2s. co m*/ * @param mecanica_id int * @return JSONObject Dados de CVideos * @since 14/01/2015 * @version 1.0 */ public Video getMecCVideos(int mecanica_id) { PreparedStatement pstmt = null; ResultSet rs = null; Connection conexao = criarConexao(); Video cVideos = null; try { String sql = "SELECT * FROM `cvideos` WHERE `cvideos`.`mecsimples_id` = " + mecanica_id; pstmt = conexao.prepareStatement(sql); rs = pstmt.executeQuery(); if (rs.next()) { cVideos = new Video(); cVideos.setVideo_id(rs.getInt("id")); cVideos.setArqVideo(rs.getString("video")); cVideos.setCapturarObjeto(new CapturarObjeto()); cVideos.getCapturarObjeto().setJogador_id(rs.getInt("jogador_id")); cVideos.getCapturarObjeto() .setPosicao(new Posicao(rs.getDouble("latitude"), rs.getDouble("longitude"))); cVideos.setMecsimples_id(rs.getInt("mecsimples_id")); } } catch (SQLException e) { System.out.println("Erro ao listar dados de uma mecanica cvideos: " + e.getMessage()); } finally { fecharConexao(conexao, pstmt, rs); } return cVideos; }
From source file:gridool.mapred.db.DBReduceJob.java
public Map<GridTask, GridNode> map(GridRouter router, DBMapReduceJobConf jobConf) throws GridException { final String inputTableName = jobConf.getMapOutputTableName(); String destTableName = jobConf.getReduceOutputTableName(); if (destTableName == null) { destTableName = generateOutputTableName(inputTableName, System.nanoTime()); jobConf.setReduceOutputTableName(destTableName); }/*from w w w . j a va 2 s. com*/ this.destTableName = destTableName; final GridNode[] nodes = router.getAllNodes(); final Map<GridTask, GridNode> map = new IdentityHashMap<GridTask, GridNode>(nodes.length); final String createTableTemplate = jobConf.getQueryTemplateForCreatingViewComposite(); if (createTableTemplate != null) { final String dstDbUrl = jobConf.getReduceOutputDbUrl(); if (dstDbUrl == null) { throw new GridException( "ReduceOutputDestinationDbUrl should be specified when using a view in reduce phase"); } final String outputTblName = jobConf.getReduceOutputTableName(); final StringBuilder createTablesQuery = new StringBuilder(512); final StringBuilder createViewQuery = new StringBuilder(512); createViewQuery.append("CREATE VIEW ").append(outputTblName).append(" AS"); final int numNodes = nodes.length; for (int i = 0; i < numNodes; i++) { if (i != 0) { createViewQuery.append(" UNION ALL"); } GridTask task = jobConf.makeReduceTask(this, inputTableName, destTableName); task.setTaskNumber(i + 1); map.put(task, nodes[i]); String newTableName = GridUtils.generateTableName(outputTblName, task); String createTableQuery = createTableTemplate.replace("?", newTableName); createTablesQuery.append(createTableQuery).append("; "); createViewQuery.append(" SELECT * FROM ").append(newTableName); } createViewQuery.append(';'); try { createView(dstDbUrl, createTablesQuery.toString(), createViewQuery.toString(), jobConf); } catch (SQLException e) { LOG.error(e.getMessage(), e); throw new GridException(e); } } else { for (GridNode node : nodes) { GridTask task = jobConf.makeReduceTask(this, inputTableName, destTableName); map.put(task, node); } } return map; }