List of usage examples for java.sql SQLException SQLException
public SQLException(String reason, Throwable cause)
SQLException
object with a given reason
and cause
. From source file:com.mycompany.parcinghtml.ParsingClassPlayers.java
public void downloadSource() throws SQLException { //ds = prepareDataSource(); String sql = "INSERT INTO PLAYERS(NAME,AGE,HEIGHT,WEIGHT,PLAYERNUM,POSITION,PLAYERID) VALUES(?,?,?,?,?,?,?)"; ArrayList<String> duplicity = new ArrayList<>(); int playerID = 1; for (int i = 2015; i > 2004; i--) { Document doc = null;/*from w ww .j a v a 2s .c o m*/ try { doc = Jsoup.connect("http://www.hcsparta.cz/soupiska.asp?sezona=" + Integer.toString(i)).get(); } catch (IOException e) { System.out.println(e.getMessage()); } if (doc == null) { System.out.println("doc is null"); return; } Elements posNum; Elements elList; posNum = doc.getElementsByAttributeValueContaining("class", "soupiska"); //elList = doc.getElementsByAttributeValueContaining("id", "soupiska"); for (int j = 0; j < 3; j++) { elList = posNum.get(j).getElementsByAttributeValueContaining("id", "soupiska"); for (Element item : elList) { String[] secondName = item.child(2).text().split(" "); if (duplicity.contains(item.child(2).text())) continue; duplicity.add(item.child(2).text()); try (Connection conn = ds.getConnection()) { try (PreparedStatement st = conn.prepareStatement(sql)) { st.setString(1, item.child(2).text()); String[] age = item.child(4).text().split(" "); st.setInt(2, Integer.parseInt(age[0])); String[] height = item.child(5).text().split(" "); st.setInt(3, Integer.parseInt(height[0])); String[] weight = item.child(6).text().split(" "); st.setInt(4, Integer.parseInt(weight[0])); try { st.setInt(5, Integer.parseInt(item.child(0).text())); } catch (NumberFormatException ex) { st.setInt(5, 0); } st.setInt(6, j); st.setInt(7, playerID); int addedRows = st.executeUpdate(); playerID++; } } catch (SQLException ex) { throw new SQLException(ex.getMessage(), ex.fillInStackTrace()); } } } } }
From source file:jp.co.tis.gsp.tools.dba.mojo.ExecuteDdlMojo.java
private void executeSql(String sql) throws SQLException { if ("".equals(sql.trim())) { return;// w ww . j a v a 2 s. co m } Statement stmt = conn.createStatement(); try { getLog().debug("SQL: " + sql); totalStatements++; stmt.execute(sql); successfulStatements++; } catch (SQLException ex) { throw new SQLException(sql, ex); } finally { StatementUtil.close(stmt); } }
From source file:com.wso2telco.util.DBConnection.java
/** * Register clients in the Database./*from w w w . j a v a 2 s . c om*/ * * @param clientDeviceId device id * @param platform platform * @param pushToken push token * @param msisdn mobile number * @throws SQLException SQLException * @throws DBUtilException DbUtilException */ public void addClient(String clientDeviceId, String platform, String pushToken, String msisdn) throws SQLException, DBUtilException { Connection connection = null; PreparedStatement statement = null; String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()); String query = "INSERT INTO clients (client_device_id,platform,push_token,date_time,msisdn) VALUES (?,?,?,?,?);"; try { connection = getConnection(); statement = connection.prepareStatement(query); statement.setString(1, clientDeviceId); statement.setString(2, platform); statement.setString(3, pushToken); statement.setString(4, timeStamp); statement.setString(5, msisdn); statement.executeUpdate(); } catch (SQLException e) { logger.error("Error occurred while inserting client details for Client Id : " + clientDeviceId + ".Error:" + e); throw new SQLException(e.getMessage(), e); } catch (DBUtilException e) { logger.error("Error occurred while inserting client details for Client Id : " + clientDeviceId + ".Error:" + e); throw new DBUtilException(e.getMessage(), e); } finally { close(connection, statement); } }
From source file:com.chiorichan.database.DatabaseEngine.java
/** * Initializes a sqLite connection./*from ww w .ja v a 2 s. co m*/ * * @param filename * @throws SQLException * @throws ClassNotFoundException */ public void init(String filename) throws SQLException { try { Class.forName("org.sqlite.JDBC"); } catch (ClassNotFoundException e) { throw new StartupException( "We could not locate the 'org.sqlite.JDBC' library, be sure to have this library in your build path."); } File sqliteDb = new File(filename); if (!sqliteDb.exists()) { getLogger().warning("The SQLite file '" + sqliteDb.getAbsolutePath() + "' did not exist, we will attempt to create a blank one now."); try { sqliteDb.createNewFile(); } catch (IOException e) { throw new SQLException( "We had a problem creating the SQLite file, the exact exception message was: " + e.getMessage(), e); } } con = DriverManager.getConnection("jdbc:sqlite:" + sqliteDb.getAbsolutePath()); getLogger().info("We succesully connected to the sqLite database using 'jdbc:sqlite:" + sqliteDb.getAbsolutePath() + "'"); type = DBType.SQLITE; }
From source file:com.couchbase.CBConnection.java
public CBConnection(String url, Properties props) throws SQLException { try {// w ww. j a va 2 s . c o m String connectionURL; if (props.containsKey(ConnectionParameters.ENABLE_SSL) && props.getProperty(ConnectionParameters.ENABLE_SSL).equals("true")) { logger.trace("Enabling SSL connection"); connectionURL = HTTPS + url.substring(14); } else { logger.trace("Normal http connection"); connectionURL = HTTP + url.substring(14); } List<NameValuePair> parameters = URLEncodedUtils.parse(new URI(connectionURL), "UTF-8"); for (NameValuePair param : parameters) { props.put(param.getName(), param.getValue()); } protocol = new ProtocolImpl(connectionURL, props); protocol.connect(); connected.set(true); } catch (Exception ex) { logger.error("Error opening connection for {} exception {}", url, ex.getMessage()); throw new SQLException("Error opening connection", ex.getCause()); } }
From source file:com.cws.esolutions.core.dao.impl.ApplicationDataDAOImpl.java
/** * @see com.cws.esolutions.core.dao.interfaces.IApplicationDataDAO#updateApplication(java.util.List) *//* ww w .ja va2s. c o m*/ public synchronized void updateApplication(final List<Object> value) throws SQLException { final String methodName = IApplicationDataDAO.CNAME + "#updateApplication(final List<Object> value) throws SQLException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", value); } Map<Integer, Object> params = new HashMap<Integer, Object>(); params.put(1, (String) value.get(0)); params.put(2, (String) value.get(1)); params.put(3, (Double) value.get(2)); params.put(4, (String) value.get(3)); params.put(5, (String) value.get(4)); params.put(6, (String) value.get(5)); params.put(7, (String) value.get(6)); params.put(8, (String) value.get(7)); params.put(9, (String) value.get(8)); try { SQLUtils.addOrDeleteData("{CALL updateApplicationData(?, ?, ?, ?, ?, ?, ?, ?, ?)}", params); } catch (UtilityException ux) { throw new SQLException(ux.getMessage(), ux); } }
From source file:org.neo4j.jdbc.http.driver.CypherExecutor.java
private String createTransactionUrl(String host, Integer port, Boolean secure) throws SQLException { try {// ww w.j a va2 s . c o m if (secure) return new URL("https", host, port, "/db/data/transaction").toString(); else return new URL("http", host, port, "/db/data/transaction").toString(); } catch (MalformedURLException e) { throw new SQLException("Invalid server URL", e); } }
From source file:com.sf.ddao.crud.param.CRUDBeanPropsParameter.java
public int bindParam(PreparedStatement preparedStatement, int idx, Context ctx) throws SQLException { if (descriptors == null) { init(ctx);// w w w. j a va 2s . c om } int c = 0; final Object bean = getBean(ctx); DirtyPropertyAware dirtyPropertyAware = null; if (bean instanceof DirtyPropertyAware) { dirtyPropertyAware = (DirtyPropertyAware) bean; } for (PropertyDescriptor descriptor : descriptors) { try { if (dirtyPropertyAware != null && !dirtyPropertyAware.isDirty(descriptor.getName())) { continue; } Object v = descriptor.getReadMethod().invoke(bean); ParameterHelper.bind(preparedStatement, idx++, v, descriptor.getPropertyType(), ctx); c++; } catch (Exception e) { throw new SQLException(descriptor.getName(), e); } } if (dirtyPropertyAware != null) { dirtyPropertyAware.cleanDirtyBean(); } return c; }
From source file:com.act.lcms.db.model.CuratedChemical.java
protected static CuratedChemical expectOneResult(ResultSet resultSet, String queryErrStr) throws SQLException { List<CuratedChemical> results = fromResultSet(resultSet); if (results.size() > 1) { throw new SQLException("Found multiple results where one or zero expected: %s", queryErrStr); }// ww w. j a v a2 s. co m if (results.size() == 0) { return null; } return results.get(0); }
From source file:com.qubole.quark.planner.parser.SqlQueryParser.java
private RelNode parseInternal(String sql) throws SQLException { try {//w w w.j a v a 2s .co m //final CalcitePrepare.Context prepareContext = context.getPrepareContext(); //Class elementType = Object[].class; //RelNode relNode = new QuarkPrepare().prepare(prepareContext, sql, elementType, -1); RelNode relNode = this.worker.parse(sql); LOG.info("\n" + RelOptUtil.dumpPlan("", relNode, false, SqlExplainLevel.ALL_ATTRIBUTES)); return relNode; } catch (CalciteContextException e) { throw new SQLException(e.getMessage(), e); } }