Java Code Examples for java.sql.SQLException

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project adbcj, under directory /jdbc/src/main/java/org/adbcj/jdbc/.

Source file: JdbcConnectionManager.java

  26 
vote

public DbFuture<Connection> connect() throws DbException {
  if (isClosed()) {
    throw new DbException("This connection manager is closed");
  }
  final DbFutureConcurrentProxy<Connection> future=new DbFutureConcurrentProxy<Connection>();
  Future<Connection> executorFuture=executorService.submit(new Callable<Connection>(){
    public Connection call() throws Exception {
      try {
        java.sql.Connection jdbcConnection=DriverManager.getConnection(jdbcUrl,properties);
        JdbcConnection connection=new JdbcConnection(JdbcConnectionManager.this,jdbcConnection);
synchronized (lock) {
          if (isClosed()) {
            connection.close(true);
            future.setException(new DbException("Connection manager closed"));
          }
 else {
            connections.add(connection);
            future.setValue(connection);
          }
        }
        return connection;
      }
 catch (      SQLException e) {
        future.setException(new DbException(e));
        e.printStackTrace();
        throw e;
      }
 finally {
        future.setDone();
      }
    }
  }
);
  future.setFuture(executorFuture);
  return future;
}
 

Example 2

From project activejdbc, under directory /activejdbc/src/test/java/org/javalite/activejdbc/mock/.

Source file: MockDataSource.java

  22 
vote

public Connection getConnection() throws SQLException {
  try {
    Class.forName(driver());
    return DriverManager.getConnection(url(),user(),password());
  }
 catch (  Exception e) {
    throw new SQLException();
  }
}
 

Example 3

From project AdminCmd, under directory /src/main/java/be/Balor/bukkit/AdminCmd/.

Source file: ACHelper.java

  17 
vote

private void dataWrapperInit(){
  if (isSqlWrapper()) {
    try {
      createTable();
      PlayerManager.getInstance().setPlayerFactory(new SQLPlayerFactory());
      WorldManager.getInstance().setWorldFactory(new SQLWorldFactory());
    }
 catch (    final SQLException e) {
      PlayerManager.getInstance().setPlayerFactory(new FilePlayerFactory(coreInstance.getDataFolder().getPath() + File.separator + "userData"));
      WorldManager.getInstance().setWorldFactory(new FileWorldFactory(coreInstance.getDataFolder().getPath() + File.separator + "worldData"));
      return;
    }
  }
 else {
    PlayerManager.getInstance().setPlayerFactory(new FilePlayerFactory(coreInstance.getDataFolder().getPath() + File.separator + "userData"));
    WorldManager.getInstance().setWorldFactory(new FileWorldFactory(coreInstance.getDataFolder().getPath() + File.separator + "worldData"));
  }
  convertFactory();
}
 

Example 4

From project AdminCmd, under directory /src/main/java/lib/SQL/PatPeter/SQLibrary/.

Source file: MySQL.java

  17 
vote

@Override protected void initialize() throws SQLException {
  try {
    Class.forName("com.mysql.jdbc.Driver");
  }
 catch (  final ClassNotFoundException e) {
    throw new SQLException("Can't load JDBC Driver",e);
  }
}
 

Example 5

From project AdServing, under directory /modules/utilities/common/src/main/java/biz/source_code/miniConnectionPoolManager/.

Source file: MiniConnectionPoolManager.java

  17 
vote

/** 
 * Closes all unused pooled connections.
 */
public synchronized void dispose() throws SQLException {
  if (isDisposed) {
    return;
  }
  isDisposed=true;
  SQLException e=null;
  while (!recycledConnections.isEmpty()) {
    PooledConnection pconn=recycledConnections.remove();
    try {
      pconn.close();
    }
 catch (    SQLException e2) {
      if (e == null) {
        e=e2;
      }
    }
  }
  if (e != null) {
    throw e;
  }
}
 

Example 6

From project agile, under directory /agile-apps/agile-app-admin/src/main/java/org/headsupdev/agile/app/admin/.

Source file: Export.java

  17 
vote

public void layout(){
  super.layout();
  add(CSSPackageResource.getHeaderContribution(getClass(),"admin.css"));
  final String exportScript=Manager.getStorageInstance().getDataDirectory() + "/agile-export.sql";
  add(new Label("location",exportScript));
  new Thread(){
    @Override public void run(){
      HibernateUtil.getCurrentSession().doWork(new Work(){
        public void execute(        Connection connection) throws SQLException {
          connection.prepareStatement("SCRIPT TO '" + exportScript + "'").execute();
        }
      }
);
    }
  }
.start();
}
 

Example 7

From project AdminCmd, under directory /src/main/java/lib/SQL/PatPeter/SQLibrary/.

Source file: SQLite.java

  16 
vote

@Override protected void initialize() throws SQLException {
  try {
    Class.forName("org.sqlite.JDBC");
    if (!sqlFile.exists()) {
      try {
        sqlFile.createNewFile();
      }
 catch (      final IOException e) {
      }
    }
  }
 catch (  final ClassNotFoundException e) {
    throw new SQLException("Can't load JDBC Driver",e);
  }
}
 

Example 8

From project AdServing, under directory /modules/services/geo/src/main/java/net/mad/ads/services/geo/.

Source file: IpinfoLocationDB.java

  16 
vote

public void open(String db) throws ClassNotFoundException, SQLException {
  this.db=db;
  Class.forName(jdbc_class_hsql);
  JDBCPooledDataSource datasource=new JDBCPooledDataSource();
  datasource.setUser("sa");
  datasource.setPassword("");
  datasource.setDatabase(jdbc_url_hsql + db);
  poolMgr=new MiniConnectionPoolManager(datasource,50);
}
 

Example 9

From project AdServing, under directory /modules/services/geo/src/main/java/net/mad/ads/services/geo/.

Source file: MaxmindIpLocationDB.java

  16 
vote

@Override public void open(String db) throws ClassNotFoundException, SQLException {
  this.db=db;
  Class.forName(jdbc_class_hsql);
  JDBCPooledDataSource datasource=new JDBCPooledDataSource();
  datasource.setUser("SA");
  datasource.setPassword("SA");
  datasource.setDatabase(jdbc_url_hsql + db);
  poolMgr=new MiniConnectionPoolManager(datasource,50);
}
 

Example 10

From project agileBase, under directory /gtpb_server/src/com/gtwm/pb/model/manageData/.

Source file: DataManagement.java

  16 
vote

/** 
 * Set the sequence generator for the ID column of a table to start at the next number above the highest value in the database. This ensures that record inserts will work
 */
private static void resetSequence(SequenceField sequenceField,Connection conn) throws SQLException {
  TableInfo table=sequenceField.getTableContainingField();
  String SQLCode="SELECT MAX(" + sequenceField.getInternalFieldName() + ") FROM "+ table.getInternalTableName();
  PreparedStatement statement=conn.prepareStatement(SQLCode);
  ResultSet results=statement.executeQuery();
  Integer maxValue=null;
  if (results.next()) {
    maxValue=results.getInt(1) + 1;
  }
 else {
    throw new SQLException("Can't get max. sequence number for field " + sequenceField);
  }
  results.close();
  statement.close();
  SQLCode="ALTER SEQUENCE " + table.getInternalTableName() + "_"+ sequenceField.getInternalFieldName()+ "_seq";
  SQLCode+=" RESTART WITH " + maxValue;
  statement=conn.prepareStatement(SQLCode);
  statement.execute();
  statement.close();
}
 

Example 11

From project agileBase, under directory /gtpb_server/src/com/gtwm/pb/model/manageSchema/.

Source file: DatabaseDefn.java

  16 
vote

/** 
 * Updates the definition of a view within the DB. This method will not work if the number of columns within the view are being changed.
 */
private boolean updateViewDbActionWithCreateOrReplace(Connection conn,BaseReportInfo report,boolean viewExists) throws SQLException, CantDoThatException, CodingErrorException, ObjectNotFoundException {
  String SQLCode="CREATE OR REPLACE VIEW " + report.getInternalReportName() + " AS ("+ report.getSQLForDetail()+ ")";
  boolean createOrReplaceWorked=true;
  Savepoint savepoint=null;
  PreparedStatement statement=null;
  try {
    savepoint=conn.setSavepoint("createOrReplaceSavepoint");
    statement=conn.prepareStatement(SQLCode);
    statement.execute();
    statement.close();
  }
 catch (  SQLException sqlex) {
    if (viewExists) {
      createOrReplaceWorked=false;
      conn.rollback(savepoint);
    }
 else {
      throw new SQLException("The requested change would cause an error in the report: " + sqlex.getMessage() + ". SQL = "+ statement,sqlex.getSQLState(),sqlex);
    }
  }
  return createOrReplaceWorked;
}
 

Example 12

From project agileBase, under directory /gtpb_server/src/com/gtwm/pb/model/manageSchema/.

Source file: DatabaseDefn.java

  16 
vote

/** 
 * Attempts to read the first 10 records from a given report, to check there isn't an error in the SQL
 */
private void throwExceptionIfDbViewIsBroken(Connection conn,BaseReportInfo report) throws SQLException, ObjectNotFoundException, CodingErrorException, CantDoThatException {
  PreparedStatement statement=null;
  try {
    ReportData.enableOptimisations(conn,report,true);
    String SQLCode="SELECT * FROM " + report.getInternalReportName() + " LIMIT 10";
    statement=conn.prepareStatement(SQLCode);
    ResultSet testResults=statement.executeQuery();
    ResultSetMetaData metaData=testResults.getMetaData();
    int numColumns=metaData.getColumnCount();
    while (testResults.next()) {
      for (int i=1; i <= numColumns; i++) {
        String testKey=testResults.getString(i);
      }
    }
    testResults.close();
    statement.close();
    ReportData.enableOptimisations(conn,report,false);
  }
 catch (  SQLException sqlex) {
    throw new SQLException("The requested change would cause an error in the report: " + sqlex.getMessage() + ". SQL = "+ statement,sqlex.getSQLState(),sqlex);
  }
}
 

Example 13

From project accesointeligente, under directory /src/org/accesointeligente/server/.

Source file: EnumUserType.java

  15 
vote

public Object nullSafeGet(ResultSet resultSet,String[] names,Object owner) throws HibernateException, SQLException {
  String name=resultSet.getString(names[0]);
  Object result=null;
  if (!resultSet.wasNull()) {
    result=Enum.valueOf(clazz,name);
  }
  return result;
}
 

Example 14

From project accesointeligente, under directory /src/org/accesointeligente/server/.

Source file: EnumUserType.java

  15 
vote

public void nullSafeSet(PreparedStatement preparedStatement,Object value,int index) throws HibernateException, SQLException {
  if (null == value) {
    preparedStatement.setNull(index,Types.VARCHAR);
  }
 else {
    preparedStatement.setString(index,((Enum)value).name());
  }
}
 

Example 15

From project activejdbc, under directory /activejdbc/src/main/java/org/javalite/activejdbc/.

Source file: RowProcessor.java

  15 
vote

protected void processRS(RowListener listener) throws SQLException {
  ResultSetMetaData metaData=rs.getMetaData();
  String labels[]=new String[metaData.getColumnCount()];
  for (int i=1; i <= labels.length; i++) {
    labels[i - 1]=metaData.getColumnLabel(i);
  }
  while (rs.next()) {
    HashMap<String,Object> row=new HashMap<String,Object>();
    for (    String label : labels) {
      row.put(label.toLowerCase(),rs.getObject(label));
    }
    if (!listener.next(row))     break;
  }
  rs.close();
  s.close();
}
 

Example 16

From project activejdbc, under directory /activejdbc/src/main/java/org/javalite/activejdbc/.

Source file: StatementCache.java

  15 
vote

PreparedStatement getPreparedStatement(Connection connection,String query) throws SQLException {
  if (!statementCache.containsKey(connection)) {
    statementCache.put(connection,new HashMap<String,PreparedStatement>());
  }
  HashMap<String,PreparedStatement> preparedStatementMap=statementCache.get(connection);
  return preparedStatementMap.get(query);
}
 

Example 17

From project adbcj, under directory /jdbc/src/main/java/org/adbcj/jdbc/.

Source file: JdbcConnection.java

  15 
vote

public boolean isClosed(){
  try {
    return closeFuture != null || jdbcConnection.isClosed();
  }
 catch (  SQLException e) {
    throw new DbException(this,e);
  }
}