List of usage examples for java.sql SQLException printStackTrace
public void printStackTrace()
From source file:com.cloudera.sqoop.manager.NetezzaExportManualTest.java
@Before public void setUp() { super.setUp(); SqoopOptions options = new SqoopOptions(NetezzaTestUtils.getNZConnectString(), getTableName()); options.setUsername(NetezzaTestUtils.getNZUser()); options.setPassword(NetezzaTestUtils.getNZPassword()); if (isDirectMode()) { this.manager = new DirectNetezzaManager(options); } else {/* w w w.j a v a 2 s .co m*/ this.manager = new NetezzaManager(options); } try { this.conn = manager.getConnection(); this.conn.setAutoCommit(false); } catch (SQLException sqlE) { LOG.error("Encountered SQL Exception: " + sqlE); sqlE.printStackTrace(); fail("SQLException when running test setUp(): " + sqlE); } }
From source file:com.jjtree.servelet.Passwords.java
@Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response);// w w w .j av a2 s . c o m JSONObject jsonObject = JConverter.convert(request); if (jsonObject == null) { return; } String account = null; String oldPassword = null; String newPassword = null; boolean isEmail = false; try { account = jsonObject.getString("account"); oldPassword = jsonObject.getString("oldPassword"); newPassword = jsonObject.getString("newPassword"); if (JString.isEmail(account)) { isEmail = true; } if (JString.isPhoneNumber(account)) { isEmail = false; } } catch (JSONException ex) { Logger.getLogger(Passwords.class.getName()).log(Level.SEVERE, null, ex); } try { // Register JDBC driver Class.forName(JConstant.JDBC_DRIVER); // Open a connection conn = DriverManager.getConnection(JConstant.DB_URL, JConstant.USER, JConstant.PASSWORD); // Execute SQL query stmt = conn.createStatement(); String sql = null; if (isEmail) { sql = "SELECT password, userID FROM JUser WHERE email ='" + account + "'"; } else { sql = "SELECT password, userID FROM JUser WHERE mobile ='" + account + "'"; } ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { String password = rs.getString(1); int accountID = rs.getInt(2); if (password.equals(oldPassword)) { if (isEmail) { sql = "UPDATE JUser SET password = '" + newPassword + "' WHERE email = '" + account + "'"; } else { sql = "UPDATE JUser SET password = '" + newPassword + "' WHERE mobile = '" + account + "'"; } stmt.executeUpdate(sql); String accountUrl = "/accounts/" + accountID; JSONObject accountObject = JServeletManager.fetchFrom(request, accountUrl); JResponse.sendJson(response, accountObject); } else { JResponse.sendErrorMessage(1, "Old password incorrect.", response); } } // Clean-up environment rs.close(); stmt.close(); conn.close(); } catch (SQLException se) { //Handle errors for JDBC se.printStackTrace(); } catch (Exception e) { //Handle errors for Class.forName e.printStackTrace(); } finally { //finally block used to close resources try { if (stmt != null) { stmt.close(); } } catch (SQLException se2) { } // nothing we can do try { if (conn != null) { conn.close(); } } catch (SQLException se) { se.printStackTrace(); } //end finally try } //end try }
From source file:com.skilrock.lms.coreEngine.scratchService.orderMgmt.common.AgentOrderProcessHelper.java
/** * This method returns a list of retailers for the passed agent * //from w w w . j a va 2 s . co m * @param agtOrgId * @return List * @throws LMSException */ public List<OrgBean> getRetailers(int agtOrgId) throws LMSException { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; String delimiter = new String("-"); try { OrgBean retailerOrgBean = null; List<OrgBean> searchResults = new ArrayList<OrgBean>(); // create database connection connection = DBConnect.getConnection(); // get fetch retailer query String query = QueryManager.getST1RetOrgQuery();// + " order by // name"; statement = connection.prepareStatement(query); statement.setInt(1, agtOrgId); resultSet = statement.executeQuery(); while (resultSet.next()) { retailerOrgBean = new OrgBean(); retailerOrgBean.setOrgId(resultSet.getInt(TableConstants.SOM_ORG_ID)); retailerOrgBean.setOrgName(resultSet.getString(TableConstants.SOM_ORG_NAME)); retailerOrgBean.setUserId(resultSet.getInt(TableConstants.SUM_USER_ID)); searchResults.add(retailerOrgBean); } return searchResults; } catch (SQLException e) { e.printStackTrace(); throw new LMSException(e); } finally { try { if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (SQLException se) { se.printStackTrace(); } } // return null; }
From source file:fr.calamus.common.db.core.DbPool.java
@Override public List<Map<String, Object>> selectMany(String sql) { ResultSet rs = null;/*from ww w . j a v a 2s . c o m*/ long time1 = System.currentTimeMillis(); Statement st = null; String usable = null; try { log(sql); usable = findAndBindUsableCnx(); st = getStatement(usable); setBusy(usable); rs = st.executeQuery(sql); } catch (SQLException e) { setLastExceptionMessage(e); e.printStackTrace(); } List<Map<String, Object>> l = Parser.getMaps(rs); if (st != null && usable != null) { busyCnxKeys.remove(usable); } long time2 = System.currentTimeMillis(); log(" time elapsed=" + (time2 - time1) + " ms"); return l; }
From source file:RowSetModel.java
public Class getColumnClass(int column) { String cname;//from ww w. j ava 2s . c o m int type; try { ResultSetMetaData meta = rowSet.getMetaData(); if (meta == null) { return null; } type = meta.getColumnType(column + 1); } catch (SQLException e) { e.printStackTrace(); return super.getColumnClass(column); } switch (type) { case Types.BIT: { cname = "java.lang.Boolean"; break; } case Types.TINYINT: { cname = "java.lang.Byte"; break; } case Types.SMALLINT: { cname = "java.lang.Short"; break; } case Types.INTEGER: { cname = "java.lang.Integer"; break; } case Types.BIGINT: { cname = "java.lang.Long"; break; } case Types.FLOAT: case Types.REAL: { cname = "java.lang.Float"; break; } case Types.DOUBLE: { cname = "java.lang.Double"; break; } case Types.NUMERIC: { cname = "java.lang.Number"; break; } case Types.DECIMAL: { cname = "java.math.BigDecimal"; break; } case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: { cname = "java.lang.String"; break; } case Types.DATE: { cname = "java.sql.Date"; break; } case Types.TIME: { cname = "java.sql.Time"; break; } case Types.TIMESTAMP: { cname = "java.sql.Timestamp"; break; } case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: { cname = "byte[]"; break; } case Types.OTHER: case Types.JAVA_OBJECT: { cname = "java.lang.Object"; break; } case Types.CLOB: { cname = "java.sql.Clob"; break; } case Types.BLOB: { cname = "java.ssql.Blob"; break; } case Types.REF: { cname = "java.sql.Ref"; break; } case Types.STRUCT: { cname = "java.sql.Struct"; break; } default: { return super.getColumnClass(column); } } try { return Class.forName(cname); } catch (Exception e) { e.printStackTrace(); return super.getColumnClass(column); } }
From source file:org.projecthdata.weight.WeightTrackerActivity.java
public void onSave(View v) { try {/*from w w w.j a v a 2 s .c o m*/ WeightReading reading = new WeightReading(); EditText weightEditText = (EditText) findViewById(R.id.weight_edit_text); Double entry = Double.parseDouble(weightEditText.getText().toString()); reading.setResultValue(entry); getDatabaseHelper().getWeightDao().create(reading); // go back to displaying the weight list getSupportFragmentManager().popBackStack(); // hide the soft keyboard InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(weightEditText.getWindowToken(), 0); } catch (SQLException e) { e.printStackTrace(); } }
From source file:com.ibm.research.rdf.store.jena.impl.DB2ResultSetImpl.java
public Binding nextBinding() { DB2Binding binding = new DB2Binding(null); nextCalled = true;/* w w w .j a v a2 s . c om*/ if (!hasNextCalled) { hasNext(); } hasNextCalled = false; if (hasNext) { Map<TypedValue, String> sidMap = new HashMap<TypedValue, String>(); try { for (int i = 0; i < varList.size(); i++) { String colName = varList.get(i); String result = null; // result = set.getString(colName.toLowerCase()); result = set.getString(colName); if (result != null) { if (result.startsWith(Constants.PREFIX_SHORT_STRING)) { if (liRs.isLiteralVariable(colName)) { short type = TypeMap.SIMPLE_LITERAL_ID; if (columnNames.contains( (colName + Constants.TYP_COLUMN_SUFFIX_IN_SPARQL_RS).toLowerCase())) { type = set.getShort( (colName + Constants.TYP_COLUMN_SUFFIX_IN_SPARQL_RS).toLowerCase()); } sidMap.put(new TypedValue(result, type), colName); } else { // this is a IRI sidMap.put(new TypedValue(result, TypeMap.IRI_ID), colName); } } else { RDFNode n = null; if (liRs.isLiteralVariable(colName)) { short type = TypeMap.SIMPLE_LITERAL_ID; if (columnNames.contains( (colName + Constants.TYP_COLUMN_SUFFIX_IN_SPARQL_RS).toLowerCase())) { type = set.getShort( (colName + Constants.TYP_COLUMN_SUFFIX_IN_SPARQL_RS).toLowerCase()); } n = new String2Node(Constants.NAME_COLUMN_OBJECT, result, type).getNode(); } else { n = new String2Node(Constants.NAME_COLUMN_SUBJECT, result).getNode(); } binding.add(Var.alloc(colName), (n != null) ? n.asNode() : null); } } } if (sidMap.size() > 0) { String sql = InsertAndUpdateStatements.getLongStringSelect(store.getLongStrings(), sidMap.size()); PreparedStatement sStmt = null; java.sql.ResultSet setSID = null; try { sStmt = connection.prepareStatement(sql); Iterator<TypedValue> sids = sidMap.keySet().iterator(); int i = 1; while (sids.hasNext()) { // mdb types // sStmt.setObject(i, sids.next()); // i++; TypedValue t = sids.next(); sStmt.setObject(i++, t.getValue()); sStmt.setObject(i++, t.getType()); } setSID = sStmt.executeQuery(); while (setSID.next()) { String sid = setSID.getString(Constants.NAME_COLUMN_SHORT_STRING.toLowerCase()); short type = setSID.getShort(Constants.NAME_COLUMN_PREFIX_TYPE.toLowerCase()); RDFNode n = new String2Node(Constants.NAME_COLUMN_OBJECT, setSID.getString(Constants.NAME_COLUMN_LONG_STRING.toLowerCase()) + setSID .getString(Constants.NAME_COLUMN_LONG_STRING_OVERFLOW.toLowerCase()), type).getNode(); binding.add(Var.alloc(sidMap.get(new TypedValue(sid, type))), n.asNode()); } } finally { DB2CloseObjects.close(setSID, sStmt); } } } catch (SQLException e) { e.printStackTrace(); } } return binding; }
From source file:com.concentricsky.android.khanacademy.util.CaptionManager.java
public List<Caption> getCaptions(String youtubeId) { Log.d(LOG_TAG, "getCaptions: " + youtubeId); List<Caption> result = null; Dao<Caption, Integer> captionDao = null; try {/*from w w w . jav a 2 s . co m*/ captionDao = dataService.getHelper().getDao(Caption.class); QueryBuilder<Caption, Integer> q = captionDao.queryBuilder(); q.where().eq("youtube_id", youtubeId); q.orderBy("sub_order", true); // TODO : Avoid inserting duplicates in the first place, and do a migration to clean up. q.groupBy("sub_order"); result = q.query(); } catch (SQLException e) { e.printStackTrace(); } if (result != null && result.size() > 0) { Log.d(LOG_TAG, " already cached; returning"); return result; } // If we do not already have the captions, try fetching them. // Clients will call this in a background thread, so we can take our time. WebResourceResponse response = fetchRawCaptionResponse(youtubeId); result = parseAPIResponse(response); result = pruneEmptyCaptions(result); result = persist(result, youtubeId); return result; }
From source file:azkaban.scheduler.JdbcScheduleLoader.java
@Override public void updateNextExecTime(Schedule s) throws ScheduleManagerException { logger.info("Update schedule " + s.getScheduleName() + " into db. "); Connection connection = getConnection(); QueryRunner runner = new QueryRunner(); try {/* ww w . ja v a 2 s . co m*/ runner.update(connection, UPDATE_NEXT_EXEC_TIME, s.getNextExecTime(), s.getScheduleId()); } catch (SQLException e) { e.printStackTrace(); logger.error(UPDATE_NEXT_EXEC_TIME + " failed.", e); throw new ScheduleManagerException("Update schedule " + s.getScheduleName() + " into db failed. ", e); } finally { DbUtils.closeQuietly(connection); } }
From source file:geo.controller.GeoCodeServlet.java
private ArrayList<MRTStation> getAllMRTStation() { try {// w w w . j a v a 2s . c o m return MRTStationDAO.getMRTList(); } catch (SQLException ex) { ex.printStackTrace(); } return null; }