List of usage examples for java.sql SQLException SQLException
public SQLException(Throwable cause)
SQLException
object with a given cause
. From source file:com.taobao.tdhs.jdbc.TDHSPreparedStatement.java
public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { if (reader == null) { setNull(parameterIndex, 0);//from w w w. j av a2s. com return; } char[] c = new char[length]; int read; try { if ((read = reader.read(c)) != length) { throw new SQLException("CharacterStream read length:" + read); } } catch (IOException e) { throw new SQLException(e); } setString(parameterIndex, new String(c)); }
From source file:org.apache.jena.jdbc.remote.connections.RemoteEndpointConnection.java
@Override protected JenaStatement createStatementInternal(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { if (this.isClosed()) throw new SQLException("Cannot create a statement after the connection was closed"); if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE) throw new SQLFeatureNotSupportedException( "Remote endpoint backed connection do not support scroll sensitive result sets"); if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) throw new SQLFeatureNotSupportedException( "Remote endpoint backed connections only support read-only result sets"); return new RemoteEndpointStatement(this, this.client, resultSetType, ResultSet.FETCH_FORWARD, 0, resultSetHoldability);//from ww w. j a v a2 s. c o m }
From source file:edu.corgi.uco.UserBean.java
public void authUser() throws SQLException { System.out.print("hit authUser"); if (dataSource == null) { throw new SQLException("DataSource is null"); }//ww w.j a v a 2 s . c o m Connection connection = dataSource.getConnection(); if (connection == null) { throw new SQLException("Connection"); } try { PreparedStatement getUser = connection .prepareStatement("select * from UserTable where authKey = ? and userid = ?"); getUser.setInt(1, token); getUser.setInt(2, userID); ResultSet results = getUser.executeQuery(); if (results.next()) { PreparedStatement setUser = connection .prepareStatement("update grouptable set groupname = 'student' where userid = ?"); setUser.setInt(1, userID); setUser.executeUpdate(); FacesContext.getCurrentInstance().addMessage("actForm:sub", new FacesMessage("Account Activated Succesfully")); } else { FacesContext.getCurrentInstance().addMessage("actForm:user", new FacesMessage("Unable to find account information")); System.out.print("no user"); } } finally { connection.close(); } }
From source file:org.jtalks.poulpe.util.databasebackup.persistence.DbTableKeys.java
/** * Obtains the list of tables foreign keys. * //www . ja v a2 s .c om * @return A list of {@link ForeignKey} object represented foreign keys. * @throws SQLException * Is thrown in case any errors during work with database occur. */ @SuppressWarnings("unchecked") public Set<ForeignKey> getForeignKeys() throws SQLException { Set<ForeignKey> tableForeignKeySet = null; try { tableForeignKeySet = (Set<ForeignKey>) JdbcUtils.extractDatabaseMetaData(dataSource, new KeyListProcessor(tableName, new TableKeyPerformer() { @Override public ResultSet getResultSet(DatabaseMetaData dmd, String tableName) throws SQLException { return dmd.getImportedKeys(null, null, tableName); } @Override public void addKeyToSet(ResultSet rs, Set<TableKey> keySet) throws SQLException { if (rs.getString(FK_NAME) != null) { keySet.add(new ForeignKey(rs.getString(FK_NAME), rs.getString(FKCOLUMN_NAME), rs.getString(PKTABLE_NAME), rs.getString(PKCOLUMN_NAME))); } } })); } catch (MetaDataAccessException e) { throw new SQLException(e); } return tableForeignKeySet; }
From source file:net.lightbody.bmp.proxy.jetty.http.JDBCUserRealm.java
private void loadUser(String username) { try {//from w w w. j a va2 s. co m if (null == _con) connectDatabase(); if (null == _con) throw new SQLException("Can't connect to database"); PreparedStatement stat = _con.prepareStatement(_userSql); stat.setObject(1, username); ResultSet rs = stat.executeQuery(); if (rs.next()) { Object key = rs.getObject(_userTableKey); put(username, rs.getString(_userTablePasswordField)); stat.close(); stat = _con.prepareStatement(_roleSql); stat.setObject(1, key); rs = stat.executeQuery(); while (rs.next()) addUserToRole(username, rs.getString(_roleTableRoleField)); stat.close(); } } catch (SQLException e) { log.warn("UserRealm " + getName() + " could not load user information from database", e); connectDatabase(); } }
From source file:com.taobao.tddl.jdbc.atom.jdbc.TStatementWrapper.java
private boolean executeInternal(String sql, int autoGeneratedKeys, int[] columnIndexes, String[] columnNames) throws SQLException { SqlType sqlType = getSqlType(sql);/* w ww.jav a 2s . co m*/ if (sqlType == SqlType.SELECT || sqlType == SqlType.SELECT_FOR_UPDATE || sqlType == SqlType.SHOW) { executeQuery(sql); return true; } else if (sqlType == SqlType.INSERT || sqlType == SqlType.UPDATE || sqlType == SqlType.DELETE || sqlType == SqlType.REPLACE || sqlType == SqlType.TRUNCATE || sqlType == SqlType.CREATE || sqlType == SqlType.DROP || sqlType == SqlType.LOAD || sqlType == SqlType.MERGE) { executeUpdateInternal(sql, autoGeneratedKeys, columnIndexes, columnNames); return false; } else { throw new SQLException( "only select, insert, update, delete,replace,truncate,create,drop,load,merge sql is supported"); } }
From source file:com.jaspersoft.jasperserver.util.JasperJdbcContainer.java
/** * Given a array of jdbc parameters and a PreparedStatment loops through the parameter array * and populates the PreparedStatement//from ww w.ja v a 2s . co m * @param params jdbc parameters extracted from a CachedRowSet * @param pstmt the PreparedStatment to populate * @throws SQLException */ private void insertParameters(Object[] params, PreparedStatement pstmt) throws SQLException { Object[] param = null; for (int i = 0; i < params.length; i++) { if (params[i] instanceof Object[]) { param = (Object[]) params[i]; if (param.length == 2) { if (param[0] == null) { pstmt.setNull(i + 1, ((Integer) param[1]).intValue()); continue; } if (param[0] instanceof java.sql.Date || param[0] instanceof java.sql.Time || param[0] instanceof java.sql.Timestamp) { if (param[1] instanceof java.util.Calendar) { pstmt.setDate(i + 1, (java.sql.Date) param[0], (java.util.Calendar) param[1]); continue; } else { throw new SQLException("Unknown Parameter, expected java.util.Calendar"); } } if (param[0] instanceof Reader) { pstmt.setCharacterStream(i + 1, (Reader) param[0], ((Integer) param[1]).intValue()); continue; } /* * What's left should be setObject(int, Object, scale) */ if (param[1] instanceof Integer) { pstmt.setObject(i + 1, param[0], ((Integer) param[1]).intValue()); continue; } } else if (param.length == 3) { if (param[0] == null) { pstmt.setNull(i + 1, ((Integer) param[1]).intValue(), (String) param[2]); continue; } // need to find and fix inputstreams if (param[0] instanceof java.io.InputStream) { //logger.fine("Found parameter of type input stream"); } //inputstream if /* * no point at looking at the first element now; what's left * must be the setObject() cases. */ if (param[1] instanceof Integer && param[2] instanceof Integer) { pstmt.setObject(i + 1, param[0], ((Integer) param[1]).intValue(), ((Integer) param[2]).intValue()); continue; } throw new SQLException("Unexpected Parameter"); } else { // common case - this catches all SQL92 types pstmt.setObject(i + 1, params[i]); continue; } } else { // Try to get all the params to be set here pstmt.setObject(i + 1, params[i]); //logger.finest("Param" + i+ ": " + params[i]); } } //for //logger.exiting(getClass().getName(), "insertParameters"); }
From source file:com.netspective.axiom.schema.constraint.BasicForeignKey.java
public Rows getReferencedRows(ConnectionContext cc, ColumnValue value) throws NamingException, SQLException { Column refColumn = getReferencedColumns().getSole(); Table refTable = refColumn.getTable(); QueryDefnSelect accessor = refColumn.getTable().getAccessorByColumnEquality(refColumn); if (accessor == null) throw new SQLException("Unable to accessor for selecting reference column " + refColumn); Object bindValue = value.getValueForSqlBindParam(); if (bindValue == null) throw new SQLException("No bind value provided for reference column " + refColumn); Rows resultRows = refTable.createRows(); QueryResultSet qrs = accessor.execute(cc, new Object[] { bindValue }, false); if (qrs != null) resultRows.populateDataByIndexes(qrs.getResultSet()); qrs.close(false);/*from w w w . j av a 2s . com*/ return resultRows; }
From source file:jp.primecloud.auto.tool.management.db.SQLExecuter.java
public Object getColumn(String sql, String columnName, String columnType) throws SQLException, Exception { Connection con = null;/*from w w w . ja v a2s . c o m*/ Statement stmt = null; ResultSet rs = null; Object object = null; log.info("[" + sql + "] ???"); try { con = dbConnector.getConnection(); stmt = con.createStatement(); rs = stmt.executeQuery(sql); while (rs.next()) { if (columnType.equals("string")) { object = rs.getString(columnName); } else if (columnType.equals("int")) { object = rs.getInt(columnName); } } log.info("[" + sql + "] ????"); } catch (SQLException e) { log.error(e.getMessage(), e); throw new SQLException(e); } catch (Exception e) { log.error(e.getMessage(), e); throw new Exception(e); } finally { try { dbConnector.closeConnection(con, stmt, rs); } catch (Exception e) { e.printStackTrace(); } } return object; }
From source file:edu.lternet.pasta.token.TokenManager.java
/** * Return the token of the user based on the uid. * * @param uid The user identifier.//w ww . j a v a2s . co m * @return A String object representing the base64 encrypted token. * @throws SQLException * @throws ClassNotFoundException */ public String getToken(String uid) throws SQLException, ClassNotFoundException { String token = null; String sql = "SELECT authtoken.tokenstore.token FROM " + "authtoken.tokenstore WHERE " + "authtoken.tokenstore.user_id='" + uid + "';"; Connection dbConn = null; // database connection object try { dbConn = getConnection(); try { Statement stmt = dbConn.createStatement(); ResultSet rs = stmt.executeQuery(sql); if (rs.next()) { token = rs.getString("token"); } else { SQLException e = new SQLException( "getToken: uid '" + uid + "' not in authtoken" + ".tokenstore"); throw (e); } } catch (SQLException e) { logger.error("getToken: " + e); logger.error(sql); e.printStackTrace(); throw (e); } finally { dbConn.close(); } // Will fail if database adapter class not found. } catch (ClassNotFoundException e) { logger.error("getToken: " + e); e.printStackTrace(); throw (e); } return token; }