List of usage examples for java.sql SQLException SQLException
public SQLException(Throwable cause)
SQLException
object with a given cause
. From source file:idgs.jdbc.IdgsClient.java
public void initConnection(HiveConf conf) throws SQLException { LOG.info("Start to initialize connection."); clientPool = TcpClientPool.getInstance(); try {/* www . jav a 2 s . c om*/ do { Object objVar = IdgsConfVars.getObjectVar(conf, IdgsConfVars.CLIENT_PB_CONFIG); if (objVar != null && objVar instanceof ClientConfig) { ClientConfig clientCfg = (ClientConfig) objVar; clientPool.loadClientConfig(clientCfg); break; } String clientCfgFilePath = IdgsConfVars.getVar(conf, IdgsConfVars.CLIENT_CONFIG_FILE); if (clientCfgFilePath != null) { clientPool.loadClientConfig(clientCfgFilePath); break; } throw new SQLException("cannot get connection from server"); } while (false); } catch (IOException e) { throw new SQLException(e); } if (clientPool.size() == 0) { LOG.error("No available server found."); throw new SQLException("No available server found."); } TcpClientInterface client = clientPool.getClient(); if (client == null) { LOG.error("Connection refused."); throw new SQLException("Connection refused."); } client.close(); }
From source file:jp.primecloud.auto.tool.management.zabbix.ZabbixSqlService.java
public void createUsergroup(String userid, String username) throws SQLException, Exception { try {//w w w . j ava 2 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:org.killbill.billing.plugin.dao.PluginDao.java
protected String asString(final Object additionalData) throws SQLException { try {//w w w . j a va2 s .com return objectMapper.writeValueAsString(additionalData); } catch (final JsonProcessingException e) { throw new SQLException(e); } }
From source file:com.jaspersoft.jasperserver.util.JasperJdbcContainer.java
/** * The main execute method which takes a connection and CachedRowSetWrapper object * extracts the command from the CachedRowSet, populates it with parameters and executes the * PreparedStatement. //from w w w . j av a 2s . c om * @param conn jdbc Connection * @param crw CachedRowSetWrapper * @throws SQLException */ public void execute(Connection conn, CachedRowSetWrapper crw) throws SQLException { long startTime = System.currentTimeMillis(); this.connection = conn; try { if (logger.isDebugEnabled()) { logger.debug("Enter execute .. Start Time" + System.currentTimeMillis()); } if (logger.isDebugEnabled()) { logger.debug("Sql query: " + crw.getCachedRowSet().getCommand()); logger.debug("Sql properties: Max Rows: " + crw.getCachedRowSet().getMaxRows()); logger.debug("Sql properties: Max Fetch Size: " + crw.getCachedRowSet().getFetchSize()); logger.debug("Sql properties: Max Fields Size: " + crw.getCachedRowSet().getMaxFieldSize()); logger.debug("Sql properties: Page Size: " + crw.getCachedRowSet().getPageSize()); } // Validate the SQL boolean isSQLValid = Validator.validateSQL(crw.getCachedRowSet().getCommand()); if (!isSQLValid) throw new SQLException("Invalid SQL:" + crw.getCachedRowSet().getCommand()); if (logger.isDebugEnabled()) { logger.debug("Sql validated successfully."); } this.preparedstatement = conn.prepareStatement(crw.getCachedRowSet().getCommand()); //set the properties on the prepstmt this.preparedstatement.setMaxRows(crw.getCachedRowSet().getMaxRows()); this.preparedstatement.setFetchSize(crw.getCachedRowSet().getFetchSize()); this.preparedstatement.setMaxFieldSize(crw.getCachedRowSet().getMaxFieldSize()); //set the parameters if present Object[] parameters = getParameters(crw.getCachedRowSet()); if (null != parameters) { insertParameters(parameters, this.preparedstatement); } if (logger.isDebugEnabled()) { logger.debug("Parameters:" + parameters.toString()); } long newStartTime = System.currentTimeMillis(); this.resultset = this.preparedstatement.executeQuery(); if (logger.isDebugEnabled()) { long newElapsedTime = System.currentTimeMillis() - newStartTime; logger.debug("Total time to execute query: " + newElapsedTime); } } catch (Exception ex) { logger.error(ex.getMessage(), ex); throw new SQLException(ex.getMessage()); } finally { if (logger.isDebugEnabled()) { long elapsedTime = System.currentTimeMillis() - startTime; logger.debug("Exit execute .. Total Time Spent: " + elapsedTime); } } }
From source file:bdManager.DBConnectionManager.java
private void initConnectionManager() throws SQLException { try {//www .ja va 2s. c o m connections = new HashMap<Long, Connection>(); properties = new Properties(); properties.load(new FileReader(this.data_location + "/db_config.properties")); if (properties.get("host") != null) { //Since version 0.8 properties.setProperty("password", new String(Base64.decodeBase64(properties.getProperty("password")))); } else { System.err.println("Old version for settings, trying to fix..."); String host = properties.get("url").toString(); host = host.replace("jdbc:mysql://", ""); host = host.replace("/" + properties.get("databasename").toString(), ""); properties.setProperty("host", host); } connectionPool = BasicDataSourceFactory.createDataSource(properties); } catch (Exception ex) { System.err.println(String.format("%tc", new Date()) + " STATEGRAEMS LOG > FAILED TRYING TO OPEN A NEW CONNECTIONS POOL"); StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); String exceptionTraceAsString = sw.toString(); System.err.println(String.format("%tc", new Date()) + " STATEGRAEMS LOG > Exception " + ex.getClass().getName() + " TRACE: " + exceptionTraceAsString); throw new SQLException("Unable to connect with DATABASE"); } }
From source file:com.treasuredata.jdbc.TDDatabaseMetaData.java
public boolean autoCommitFailureClosesAllResultSets() throws SQLException { throw new SQLException("Unsupported TDDatabaseMetaData#autoCommitFailureClosesAllResultSets()"); }
From source file:org.apache.jena.jdbc.remote.statements.RemoteEndpointPreparedStatement.java
@Override protected QueryExecution createQueryExecution(Query q) throws SQLException { if (this.remoteConn.getQueryEndpoint() == null) throw new SQLException( "This statement is backed by a write-only connection, read operations are not supported"); // Create basic execution QueryEngineHTTP exec = (QueryEngineHTTP) QueryExecutionFactory .sparqlService(this.remoteConn.getQueryEndpoint(), q); // Apply HTTP settings if (this.client != null) { exec.setClient(this.client); }/*from w ww.jav a2 s .com*/ // Apply default and named graphs if appropriate if (this.remoteConn.getDefaultGraphURIs() != null) { exec.setDefaultGraphURIs(this.remoteConn.getDefaultGraphURIs()); } if (this.remoteConn.getNamedGraphURIs() != null) { exec.setNamedGraphURIs(this.remoteConn.getNamedGraphURIs()); } // Set result types if (this.remoteConn.getSelectResultsType() != null) { exec.setSelectContentType(this.remoteConn.getSelectResultsType()); } if (this.remoteConn.getModelResultsType() != null) { exec.setModelContentType(this.remoteConn.getModelResultsType()); } // Return execution return exec; }
From source file:fr.paris.lutece.util.sql.MultiPluginTransaction.java
/** * {@inheritDoc}// w ww . ja v a2 s. com */ @Override public PreparedStatement prepareStatement(String strSQL) throws SQLException { // Get a new statement if (getConnection() == null) { throw new SQLException( "MultiPluginTransaction - Connection has been closed. The new prepared statement can not be created : " + strSQL); } return getConnection().prepareStatement(strSQL); }
From source file:com.sf.ddao.factory.param.ParameterHelper.java
public static void bind(PreparedStatement preparedStatement, int idx, Object param, Class<?> clazz, Context context) throws SQLException { if (clazz == Integer.class || clazz == Integer.TYPE) { preparedStatement.setInt(idx, (Integer) param); } else if (clazz == String.class) { preparedStatement.setString(idx, (String) param); } else if (clazz == Long.class || clazz == Long.TYPE) { preparedStatement.setLong(idx, (Long) param); } else if (clazz == Boolean.class || clazz == Boolean.TYPE) { preparedStatement.setBoolean(idx, (Boolean) param); } else if (BigInteger.class.isAssignableFrom(clazz)) { BigInteger bi = (BigInteger) param; preparedStatement.setBigDecimal(idx, new BigDecimal(bi)); } else if (Timestamp.class.isAssignableFrom(clazz)) { preparedStatement.setTimestamp(idx, (Timestamp) param); } else if (Date.class.isAssignableFrom(clazz)) { if (!java.sql.Date.class.isAssignableFrom(clazz)) { param = new java.sql.Date(((Date) param).getTime()); }// w w w . j a v a 2 s .c o m preparedStatement.setDate(idx, (java.sql.Date) param); } else if (BoundParameter.class.isAssignableFrom(clazz)) { ((BoundParameter) param).bindParam(preparedStatement, idx, context); } else { throw new SQLException("Unimplemented type mapping for " + clazz); } }
From source file:ch.digitalfondue.npjt.ConstructorAnnotationRowMapper.java
@Override public T mapRow(ResultSet rs, int rowNum) throws SQLException { Object[] vals = new Object[mappedColumn.length]; for (int i = 0; i < mappedColumn.length; i++) { vals[i] = mappedColumn[i].getObject(rs); }/* w ww.ja v a 2 s.c o m*/ try { return con.newInstance(vals); } catch (ReflectiveOperationException e) { throw new SQLException(e); } catch (IllegalArgumentException e) { throw new SQLException("type mismatch between the expected one from the construct and the one passed," + " check 1: some values are null and passed to primitive types 2: incompatible numeric types", e); } }