List of usage examples for java.sql SQLException printStackTrace
public void printStackTrace()
From source file:edu.byu.wso2.apim.extensions.helpers.BYUEntityHelper.java
public BYUEntity getBYUEntityFromPersonId(String personid) { Connection con = null;/*from w w w . j a v a 2s .c o m*/ Statement statement = null; ResultSet resultSet = null; BYUEntity byuEntity = null; try { con = ds.getConnection(); if (log.isDebugEnabled()) log.debug("connection acquired. creating statement and executing query"); statement = con.createStatement(); resultSet = statement.executeQuery("select * from pro.person where person_id = '" + personid + "'"); if (resultSet.next()) { String byu_id = resultSet.getString("byu_id"); String person_id = resultSet.getString("person_id"); String net_id = resultSet.getString("net_id"); String surname = resultSet.getString("surname"); String rest_of_name = resultSet.getString("rest_of_name"); if (log.isDebugEnabled()) log.debug("byu_id: " + byu_id + " person_id: " + person_id + " surname: " + surname + " rest_of_name: " + rest_of_name); byuEntity = new BYUEntity(net_id, person_id, byu_id, surname, rest_of_name); } else { if (log.isDebugEnabled()) { log.debug("resultset is empty"); } } } catch (SQLException e) { e.printStackTrace(); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { /* ignored */ } } if (statement != null) { try { statement.close(); } catch (SQLException e) { /* ignored */ } } if (con != null) { try { con.close(); } catch (SQLException e) { /* ignored */ } } } return byuEntity; }
From source file:eu.supersede.fe.multitenant.MultiJpaProvider.java
@PostConstruct private void load() { Map<String, DataSource> datasources = dataSourceBasedMultiTenantConnectionProviderImpl.getDataSources(); repositoriesFactory = new HashMap<>(); for (String n : datasources.keySet()) { try {/* ww w . j av a 2 s .c om*/ log.info("Loading database: " + datasources.get(n).getConnection().getMetaData().getURL()); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } Map<String, Object> hibernateProps = new LinkedHashMap<>(); hibernateProps.putAll(jpaProperties.getHibernateProperties(datasources.get(n))); hibernateProps.put(Environment.DIALECT, "org.hibernate.dialect.PostgreSQLDialect"); Set<String> packages = new HashSet<>(); String[] tmp = MODELS_PACKAGES.split(","); for (String t : tmp) { packages.add(t.trim()); } LocalContainerEntityManagerFactoryBean emfb = builder.dataSource(datasources.get(n)) .packages(packages.toArray(new String[packages.size()])).properties(hibernateProps).jta(false) .build(); emfb.afterPropertiesSet(); EntityManagerFactory emf = emfb.getObject(); EntityManager em = emf.createEntityManager(); final JpaTransactionManager jpaTranMan = new JpaTransactionManager(emf); JpaRepositoryFactory jpaFactory = new JpaRepositoryFactory(em); jpaFactory.addRepositoryProxyPostProcessor(new MultiJpaRepositoryProxyPostProcessor(jpaTranMan)); repositoriesFactory.put(n, new ContainerUtil(jpaFactory, emf, em)); } }
From source file:at.alladin.rmbt.controlServer.NewsResource.java
@Post("json") public String request(final String entity) { addAllowOrigin();/* w w w. j a va 2s. co m*/ 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:ca.fastenalcompany.servlet.ProductServlet.java
public int update(String query, String... params) { Connection conn = null;/* w w w .jav a 2s . co m*/ int result = -1; try { conn = DBManager.getMysqlConn(); PreparedStatement pstmt = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); } System.out.println(query); int rowsEffected = pstmt.executeUpdate(); ResultSet rs = pstmt.getGeneratedKeys(); if (rs.next()) { result = rs.getInt(1); } else if (rowsEffected > 0) { result = Integer.parseInt(params[params.length - 1]); } } catch (SQLException ex) { ex.printStackTrace(); } finally { try { System.out.println("DB connection closed"); if (conn != null) { conn.close(); } } catch (SQLException ex) { ex.printStackTrace(); } } return result; }
From source file:edu.purdue.pivot.skwiki.server.ImageUploaderServlet.java
/** * Get the content of an uploaded file.//from w w w . j ava2 s .c o m */ @Override public void getUploadedFile(HttpServletRequest request, HttpServletResponse response) throws IOException { String fieldName = request.getParameter(UConsts.PARAM_SHOW); //File f = receivedFiles.get(fieldName); String selectStr = "select path from images where field_name = \'" + fieldName + "\'"; Statement st = null; ResultSet rs = null; ResultSet rst = null; String receivedFilePath = receivedFilePaths.get(fieldName); try { st = connection.createStatement(); rs = st.executeQuery(selectStr); while (rs.next()) { receivedFilePath = rs.getString(1); } } catch (SQLException e) { e.printStackTrace(); } File f = new File(receivedFilePath); if (f != null) { response.setContentType(receivedContentTypes.get(fieldName)); FileInputStream is = new FileInputStream(f); copyFromInputStreamToOutputStream(is, response.getOutputStream()); } else { renderXmlResponse(request, response, XML_ERROR_ITEM_NOT_FOUND); } }
From source file:com.handu.open.dubbo.monitor.dao.base.DubboInvokeBaseDAO.java
/** * SQL?/*from ww w.j a va 2 s . c o m*/ * * @param sql SQL? * @return List<Map> */ public List<Map> querySql(String sql) { List<Map> list = Lists.newArrayList(); try { ResultSet rs = getSqlSession().getConnection() .prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE) .executeQuery(); try { ResultSetMetaData rsm = rs.getMetaData(); // int col = rsm.getColumnCount(); // String[] colName = new String[col]; //???, colName for (int i = 0; i < col; i++) { colName[i] = rsm.getColumnName(i + 1); } rs.beforeFirst(); while (rs.next()) { Map<String, String> map = Maps.newHashMap(); for (String aColName : colName) { map.put(aColName, rs.getString(aColName)); } list.add(map); } } catch (SQLException e) { e.printStackTrace(); return null; } } catch (SQLException e) { e.printStackTrace(); } return list; }
From source file:azkaban.trigger.JdbcTriggerLoaderTest.java
public void setupDB() { DataSource dataSource = DataSourceUtils.getMySQLDataSource(host, port, database, user, password, numConnections);//from w w w. j a v a2 s. co m testDBExists = true; Connection connection = null; try { connection = dataSource.getConnection(); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } CountHandler countHandler = new CountHandler(); QueryRunner runner = new QueryRunner(); try { runner.query(connection, "SELECT COUNT(1) FROM triggers", countHandler); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } DbUtils.closeQuietly(connection); clearDB(); }
From source file:edu.byu.wso2.apim.extensions.helpers.BYUEntityHelper.java
public BYUEntity getBYUEntityFromConsumerKey(String consumerKey) { Connection con = null;/*from w ww . j a v a2 s .co m*/ Statement statement = null; ResultSet resultSet = null; BYUEntity byuEntity = null; try { con = ds.getConnection(); if (log.isDebugEnabled()) log.debug("connection acquired. creating statement and executing query"); statement = con.createStatement(); resultSet = statement .executeQuery("select * from pro.person p, iam.credential c where p.byu_id = c.byu_id " + "and c.credential_type = 'WSO2_CLIENT_ID' and c.credential_id = '" + consumerKey + "'"); if (resultSet.next()) { String byu_id = resultSet.getString("byu_id"); String person_id = resultSet.getString("person_id"); String net_id = resultSet.getString("net_id"); String surname = resultSet.getString("surname"); String rest_of_name = resultSet.getString("rest_of_name"); if (log.isDebugEnabled()) log.debug("byu_id: " + byu_id + " person_id: " + person_id + " surname: " + surname + " rest_of_name: " + rest_of_name); byuEntity = new BYUEntity(net_id, person_id, byu_id, surname, rest_of_name); } else { if (log.isDebugEnabled()) { log.debug("resultset is empty"); } } } catch (SQLException e) { e.printStackTrace(); } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { /* ignored */ } } if (statement != null) { try { statement.close(); } catch (SQLException e) { /* ignored */ } } if (con != null) { try { con.close(); } catch (SQLException e) { /* ignored */ } } } return byuEntity; }
From source file:azkaban.trigger.JdbcTriggerLoaderTest.java
@After public void clearDB() { if (!testDBExists) { return;//from ww w.j ava2 s .c o m } DataSource dataSource = DataSourceUtils.getMySQLDataSource(host, port, database, user, password, numConnections); Connection connection = null; try { connection = dataSource.getConnection(); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } QueryRunner runner = new QueryRunner(); try { runner.update(connection, "DELETE FROM triggers"); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } DbUtils.closeQuietly(connection); }
From source file:ca.fastenalcompany.servlet.ProductServlet.java
public JSONArray query(String query, String... params) { Connection conn = null;//from w w w. j a v a 2 s . co m JSONArray products = new JSONArray(); try { conn = DBManager.getMysqlConn(); PreparedStatement pstmt = conn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); } System.out.println(query); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { JSONObject product = new JSONObject(); for (int i = 1; i < rs.getMetaData().getColumnCount() + 1; i++) { String textLabel = rs.getMetaData().getColumnLabel(i); String textValue = rs.getString(textLabel); product.put(textLabel, textValue); } products.add(product); } } catch (SQLException ex) { ex.printStackTrace(); } finally { try { System.out.println("DB connection closed"); if (conn != null) { conn.close(); } } catch (SQLException ex) { ex.printStackTrace(); } } return products; }