List of usage examples for java.sql SQLException toString
public String toString()
From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java
@Test public void ResultSetMetadata() { try {// www .j a v a2s. c om this.logger.debug(BQResultSetFunctionTest.Result.getMetaData().getSchemaName(1)); this.logger.debug(BQResultSetFunctionTest.Result.getMetaData().getScale(1)); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); } Assert.assertTrue(true); }
From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java
@Test public void TestResultSetFirst() { try {//w w w. j a v a 2 s. c o m Assert.assertTrue(BQResultSetFunctionTest.Result.first()); Assert.assertTrue(BQResultSetFunctionTest.Result.isFirst()); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } }
From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java
@Test public void TestResultSetgetBoolean() { try {/*from ww w. ja v a 2 s .c o m*/ Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(1)); Assert.assertEquals(Boolean.parseBoolean("42"), BQResultSetFunctionTest.Result.getBoolean(2)); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } }
From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java
@Test public void TestResultSetgetFloat() { try {/* ww w . j av a2 s . co m*/ Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(1)); Assert.assertEquals(new Float(42), BQResultSetFunctionTest.Result.getFloat(2)); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } }
From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java
@Test public void TestResultSetgetInteger() { try {//ww w . j a va2 s . c o m Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(1)); Assert.assertEquals(42, BQResultSetFunctionTest.Result.getInt(2)); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } }
From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java
@Test public void TestResultSetLast() { try {/*from ww w. j a v a 2 s .com*/ Assert.assertTrue(BQResultSetFunctionTest.Result.last()); Assert.assertTrue(BQResultSetFunctionTest.Result.isLast()); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } }
From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java
@Test public void TestResultSetgetString() { try {/*from w w w .j av a 2s. co m*/ Assert.assertTrue(BQResultSetFunctionTest.Result.first()); Assert.assertEquals("you", BQResultSetFunctionTest.Result.getString(1)); Assert.assertTrue(BQResultSetFunctionTest.Result.last()); Assert.assertEquals("word", BQResultSetFunctionTest.Result.getString(1)); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } }
From source file:at.alladin.rmbt.controlServer.NewsResource.java
@Post("json") public String request(final String entity) { addAllowOrigin();/*from w ww . jav a 2s. c om*/ JSONObject request = null; final ErrorList errorList = new ErrorList(); final JSONObject answer = new JSONObject(); String answerString; System.out.println(MessageFormat.format(labels.getString("NEW_NEWS"), getIP())); if (entity != null && !entity.isEmpty()) // try parse the string to a JSON object try { request = new JSONObject(entity); String lang = request.optString("language"); // Load Language Files for Client final List<String> langs = Arrays .asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*")); if (langs.contains(lang)) { errorList.setLanguage(lang); labels = ResourceManager.getSysMsgBundle(new Locale(lang)); } else lang = settings.getString("RMBT_DEFAULT_LANGUAGE"); String sqlLang = lang; if (!sqlLang.equals("de")) sqlLang = "en"; if (conn != null) { final long lastNewsUid = request.optLong("lastNewsUid"); final String plattform = request.optString("plattform"); final int softwareVersionCode = request.optInt("softwareVersionCode", -1); String uuid = request.optString("uuid"); final JSONArray newsList = new JSONArray(); try { final PreparedStatement st = conn.prepareStatement("SELECT uid,title_" + sqlLang + " AS title, text_" + sqlLang + " AS text FROM news " + " WHERE" + " (uid > ? OR force = true)" + " AND active = true" + " AND (plattform IS NULL OR plattform = ?)" + " AND (max_software_version_code IS NULL OR ? <= max_software_version_code)" + " AND (min_software_version_code IS NULL OR ? >= min_software_version_code)" + " AND (uuid IS NULL OR uuid::TEXT = ?)" + //convert to text so that empty uuid-strings are tolerated " ORDER BY time ASC"); st.setLong(1, lastNewsUid); st.setString(2, plattform); st.setInt(3, softwareVersionCode); st.setInt(4, softwareVersionCode); st.setString(5, uuid); final ResultSet rs = st.executeQuery(); while (rs.next()) { final JSONObject jsonItem = new JSONObject(); jsonItem.put("uid", rs.getInt("uid")); jsonItem.put("title", rs.getString("title")); jsonItem.put("text", rs.getString("text")); newsList.put(jsonItem); } rs.close(); st.close(); } catch (final SQLException e) { e.printStackTrace(); errorList.addError("ERROR_DB_GET_NEWS_SQL"); } // } answer.put("news", newsList); } else errorList.addError("ERROR_DB_CONNECTION"); } catch (final JSONException e) { errorList.addError("ERROR_REQUEST_JSON"); System.out.println("Error parsing JSON Data " + e.toString()); } else errorList.addErrorString("Expected request is missing."); try { answer.putOpt("error", errorList.getList()); } catch (final JSONException e) { System.out.println("Error saving ErrorList: " + e.toString()); } answerString = answer.toString(); return answerString; }
From source file:com.redoute.datamap.dao.impl.DatamapDAO.java
@Override public Integer getNumberOfDatamapPerCrtiteria(String searchTerm, String inds) { Integer result = 0;/* w w w.jav a 2 s.com*/ StringBuilder query = new StringBuilder(); StringBuilder gSearch = new StringBuilder(); String searchSQL = ""; query.append("SELECT count(*) FROM datamap"); gSearch.append(" where (`id` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `page` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `application` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `stream` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `implemented` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `zone` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `picture` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `comment` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `locationTYpe` like '%"); gSearch.append(searchTerm); gSearch.append("%'"); gSearch.append(" or `locationValue` like '%"); gSearch.append(searchTerm); gSearch.append("%')"); if (!searchTerm.equals("") && !inds.equals("")) { searchSQL = gSearch.toString() + " and " + inds; } else if (!inds.equals("")) { searchSQL = " where " + inds; } else if (!searchTerm.equals("")) { searchSQL = gSearch.toString(); } query.append(searchSQL); Connection connection = this.databaseSpring.connect(); try { PreparedStatement preStat = connection.prepareStatement(query.toString()); try { ResultSet resultSet = preStat.executeQuery(); try { if (resultSet.first()) { result = resultSet.getInt(1); } } catch (SQLException exception) { Logger.log(DatamapDAO.class.getName(), Level.ERROR, exception.toString()); } finally { resultSet.close(); } } catch (SQLException exception) { Logger.log(DatamapDAO.class.getName(), Level.ERROR, exception.toString()); } finally { preStat.close(); } } catch (SQLException exception) { Logger.log(DatamapDAO.class.getName(), Level.ERROR, exception.toString()); } finally { try { if (connection != null) { connection.close(); } } catch (SQLException e) { Logger.log(DatamapDAO.class.getName(), Level.ERROR, e.toString()); } } return result; }
From source file:BQJDBC.QueryResultTest.BQScrollableResultSetFunctionTest.java
public void QueryLoad() { final String sql = "SELECT TOP(word,10) AS word, COUNT(*) as count FROM publicdata:samples.shakespeare"; final String description = "The top 10 word from shakespeare #TOP #COUNT"; String[][] expectation = new String[][] { { "you", "yet", "would", "world", "without", "with", "your", "young", "words", "word" }, { "42", "42", "42", "42", "42", "42", "41", "41", "41", "41" } }; /** somehow the result changed with time { "you", "yet", "would", "world", "without", "with", "will", "why", "whose", "whom" },/*from ww w . j av a 2s . c om*/ { "42", "42", "42", "42", "42", "42", "42", "42", "42", "42" } }; */ this.logger.info("Test number: 01"); this.logger.info("Running query:" + sql); try { //Statement stmt = BQResultSetFunctionTest.con.createStatement(); Statement stmt = BQScrollableResultSetFunctionTest.con .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); stmt.setQueryTimeout(500); BQScrollableResultSetFunctionTest.Result = stmt.executeQuery(sql); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } Assert.assertNotNull(BQScrollableResultSetFunctionTest.Result); this.logger.debug(description); HelperFunctions.printer(expectation); try { Assert.assertTrue("Comparing failed in the String[][] array", this.comparer(expectation, BQSupportMethods.GetQueryResult(BQScrollableResultSetFunctionTest.Result))); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail(e.toString()); } }