List of usage examples for java.sql SQLException SQLException
public SQLException(Throwable cause)
SQLException
object with a given cause
. From source file:fr.paris.lutece.util.sql.Transaction.java
/** * Gets a prepared statement/*from ww w. ja v a2 s.co m*/ * @param strSQL The SQL statement * @return The prepared statement * @throws SQLException If an SQL error occurs */ public PreparedStatement prepareStatement(String strSQL) throws SQLException { // Close the previous statement if exists if (_statement != null) { _statement.close(); } // Get a new statement _strSQL = strSQL; if (_connection == null) { throw new SQLException("Plugin : '" + _strPluginName + "' - Connection has been closed. The new prepared statement can not be created : " + strSQL); } _statement = _connection.prepareStatement(_strSQL); return _statement; }
From source file:com.flexive.core.Database.java
/** * Retrieves a database connection.// ww w .j ava 2s .co m * * @param divisionId the requested division Id * @return a database connection * @throws SQLException If no connection could be retrieved */ public static Connection getDbConnection(int divisionId) throws SQLException { // Try to obtain a connection try { return getDataSource(divisionId, true).getConnection(); } catch (SQLException exc) { String sErr = "FxDbException, unable to retrieve DB Connection: " + exc.getMessage(); LOG.error(sErr); throw new SQLException(sErr); } }
From source file:com.taobao.adfs.database.tdhsocket.client.response.TDHSResutSet.java
private void checkType(int columnIndex) throws SQLException { if (columnIndex <= 0 || columnIndex > fieldTypes.size()) { throw new SQLException("Invaild column:" + columnIndex); }/* w ww .j av a2s . c o m*/ }
From source file:es.tid.fiware.rss.exceptionhandles.FactoryResponseTest.java
/** * /*from w w w . j a v a 2 s.co m*/ */ @Test public void catchNewConnectionJson() throws Exception { UriInfo mockUriInfo = Mockito.mock(UriInfo.class); Mockito.when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://www.test.com/go")); GenericJDBCException exception = new GenericJDBCException("sql", new SQLException("reason")); Response bean = FactoryResponse.catchNewConnectionJson(rssProps, mockUriInfo, exception, "message", "resource"); Assert.assertTrue(true); }
From source file:com.arsmentis.cordova.jdbc.Jdbc.java
private JSONArray execute(String sql) throws SQLException, JSONException { if (connection == null) { throw new SQLException("Not connected"); }/* ww w .j a v a 2 s.c o m*/ JSONArray results = new JSONArray(); Statement statement = connection.createStatement(); if (statement.execute(sql)) { ResultSet resultSet = statement.getResultSet(); ResultSetMetaData columns = resultSet.getMetaData(); while (resultSet.next()) { JSONObject row = new JSONObject(); for (int i = 1; i <= columns.getColumnCount(); i++) { row.put(columns.getColumnName(i), resultSet.getObject(i)); } results.put(row); } resultSet.close(); } statement.close(); return results; }
From source file:com.adaptris.core.services.jdbc.JdbcBatchingDataCaptureService.java
protected static long rowsUpdated(int[] rc) throws SQLException { List<Integer> result = Arrays.asList(ArrayUtils.toObject(rc)); if (result.contains(Statement.EXECUTE_FAILED)) { throw new SQLException("Batch Execution Failed."); }/*from w w w .jav a 2 s .c o m*/ return result.stream().filter(e -> !(e == Statement.SUCCESS_NO_INFO)).mapToLong(i -> i).sum(); }
From source file:jp.primecloud.auto.tool.management.zabbix.ZabbixSqlService.java
public void updateUsergroup(String username, int enableFlag) throws SQLException, Exception { //status 0:enable 1:disable String updateUsergroup = "update usrgrp SET users_status =" + enableFlag + " where name ='" + username + "'"; try {/*from www . ja va 2s.c om*/ sqlExecuter.execute(updateUsergroup); } 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:es.tid.fiware.rss.expenditureLimit.server.manager.common.test.FactoryResponseTest.java
/** * /*from w w w . jav a2s .c o m*/ */ @Test public void catchNewConnectionJson() throws Exception { UriInfo mockUriInfo = Mockito.mock(UriInfo.class); Mockito.when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://www.test.com/go")); GenericJDBCException exception = new GenericJDBCException("sql", new SQLException("reason")); Response bean = FactoryResponse.catchNewConnectionJson(appProperties, mockUriInfo, exception, "message", "resource"); Assert.assertTrue(true); }
From source file:com.treasuredata.jdbc.TDDatabaseMetaData.java
public boolean deletesAreDetected(int type) throws SQLException { throw new SQLException("Unsupported TDDatabaseMetaData#deletesAreDetected(int)"); }
From source file:com.oltpbenchmark.benchmarks.wikirest.procedures.GetPageAnonymousRest.java
public Article run(Builder builder, boolean forSelect, String userIp, int pageNamespace, String pageTitle) throws UserAbortException, SQLException, JSONException { int param = 1; this.builder = builder; String selectPage = selectPageWithVariables; selectPage = StringUtils.replaceOnce(selectPage, SQL_VARIABLE, Integer.toString(pageNamespace)); selectPage = StringUtils.replaceOnce(selectPage, SQL_VARIABLE, pageTitle); ClientResponse response = getClient().post(ClientResponse.class, selectPage); if (response.getClientResponseStatus() != com.sun.jersey.api.client.ClientResponse.Status.OK) { throw new SQLException("Query " + selectPage + " encountered an error "); }// w ww . j a va 2 s .c o m JSONArray jsonArray = response.getEntity(JSONArray.class); response.close(); if (jsonArray.length() == 0) { String msg = String.format("Invalid Page: Namespace:%d / Title:--%s--", pageNamespace, pageTitle); throw new UserAbortException(msg); } int pageId = jsonArray.getJSONObject(0).optInt("page_id"); // selectPageRestriction String selectPageRestriction = selectPageRestrictionWithVariables; selectPageRestriction = StringUtils.replaceOnce(selectPageRestriction, SQL_VARIABLE, Integer.toString(pageId)); response = getClient().post(ClientResponse.class, selectPageRestriction); if (response.getClientResponseStatus() != com.sun.jersey.api.client.ClientResponse.Status.OK) { throw new SQLException("Query " + selectPageRestriction + " encountered an error "); } jsonArray = response.getEntity(JSONArray.class); response.close(); if (jsonArray.length() == 0 || !jsonArray.getJSONObject(0).has("pr_page")) { String msg = String.format("Invalid Page: ID:%d ", pageId); throw new UserAbortException(msg); } // selectIP Block String selectIpBlocks = selectIpBlocksWithVariables; selectIpBlocks = StringUtils.replaceOnce(selectIpBlocks, SQL_VARIABLE, userIp); response = getClient().post(ClientResponse.class, selectIpBlocks); if (response.getClientResponseStatus() != com.sun.jersey.api.client.ClientResponse.Status.OK) { throw new SQLException("Query " + selectIpBlocks + " encountered an error "); } jsonArray = response.getEntity(JSONArray.class); response.close(); if (jsonArray.length() == 0 || !jsonArray.getJSONObject(0).has("ipb_id")) { String msg = String.format("Invalid IP Block: Ip:%d ", userIp); throw new UserAbortException(msg); } // selectPageRevision String selectPageRevision = selectPageRevisionWithVariables; selectPageRevision = StringUtils.replaceOnce(selectPageRevision, SQL_VARIABLE, Integer.toString(pageId)); selectPageRevision = StringUtils.replaceOnce(selectPageRevision, SQL_VARIABLE, Integer.toString(pageId)); response = getClient().post(ClientResponse.class, selectPageRevision); if (response.getClientResponseStatus() != com.sun.jersey.api.client.ClientResponse.Status.OK) { throw new SQLException("Query " + selectPageRevision + " encountered an error "); } jsonArray = response.getEntity(JSONArray.class); response.close(); if (jsonArray.length() == 0) { String msg = String.format("Invalid Page: Namespace:%d / Title:--%s-- / PageId:%d", pageNamespace, pageTitle, pageId); throw new UserAbortException(msg); } int revisionId = jsonArray.getJSONObject(0).optInt("rev_id"); int textId = jsonArray.getJSONObject(0).optInt("rev_text_id"); ; // NOTE: the following is our variation of wikipedia... the original did // not contain old_page column! // sql = // "SELECT old_text,old_flags FROM `text` WHERE old_id = '"+textId+"' // AND old_page = '"+pageId+"' LIMIT 1"; // For now we run the original one, which works on the data we have String selectText = selectTextWithVariables; selectText = StringUtils.replaceOnce(selectText, SQL_VARIABLE, Integer.toString(textId)); response = getClient().post(ClientResponse.class, selectText); if (response.getClientResponseStatus() != com.sun.jersey.api.client.ClientResponse.Status.OK) { throw new SQLException("Query " + selectText + " encountered an error "); } jsonArray = response.getEntity(JSONArray.class); response.close(); if (jsonArray.length() == 0) { String msg = "No such text: " + textId + " for page_id:" + pageId + " page_namespace: " + pageNamespace + " page_title:" + pageTitle; throw new UserAbortException(msg); } Article a = null; if (!forSelect) a = new Article(userIp, pageId, jsonArray.getJSONObject(0).optString("old_text"), textId, revisionId); return a; }