List of usage examples for java.sql SQLException printStackTrace
public void printStackTrace()
From source file:com.pivotal.gfxd.demo.services.PredictionService.java
public float currentLoad(long timestamp, TimeSlice.Interval interval) { TimeSlice slice = new TimeSlice(timestamp, interval); try {//from www. j ava 2s. com return getAverageLoad(OPERATIONAL_AVG_OVERALL_QUERY, slice.getWeekday(), slice.getIntervalStart(), slice.getIntervalEnd(), 0); } catch (SQLException e) { e.printStackTrace(); } return 0; }
From source file:com.silverpeas.wysiwyg.dynamicvalue.AbstractBaseDynamicValue.java
/** * @throws java.lang.Exception/*from w w w .ja v a 2s. co m*/ */ @Before @Override public void setUp() throws Exception { properties = new Properties(); properties.load(TestDynamicValueDAO.class.getClassLoader().getResourceAsStream("jdbc.properties")); // create the table to execute the test Connection con = null; Statement statement = null; try { con = getConnection().getConnection(); statement = con.createStatement(); try { statement.executeUpdate("DROP TABLE val_dyn1"); } catch (SQLException e) { e.printStackTrace(); } String sql = "CREATE TABLE val_dyn1 ( \"value\" character varying(256) NOT NULL," + "keyword character varying(100) NOT NULL, start_date date NOT NULL, end_date date )" + "WITH (OIDS=FALSE);" + "ALTER TABLE val_dyn1 OWNER TO " + getUsername(); statement.executeUpdate(sql); } finally { DBUtil.close(statement); DBUtil.close(con); } super.setUp(); }
From source file:json.UserController.java
@RequestMapping(value = "/createUserService", method = RequestMethod.POST, produces = "application/json") public @ResponseBody AuthenticationResponse createUser(@RequestBody User user) { Connection conn = null;/*from w w w. ja v a 2 s . c o m*/ PreparedStatement stmt = null; ResultSet rs = null; String query = "INSERT INTO user (username, userPassword, emailAddress, fullName, contactNo, nricType, nric, dob, gender, blkStreetUnit, postalCode) VALUES (?,?,?,?,?,?,?,?,?,?,?)"; System.out.println("user" + query); try { //Set up connection with database conn = ConnectionManager.getConnection(); stmt = conn.prepareStatement(query); stmt.setString(1, user.getUsername()); stmt.setString(2, user.getPassword()); stmt.setString(3, user.getEmailAddress()); stmt.setString(4, user.getFullname()); stmt.setString(5, user.getContactNo()); stmt.setString(6, user.getNricType()); stmt.setString(7, user.getNric()); stmt.setString(8, user.getDob()); stmt.setString(9, user.getGender()); stmt.setString(10, user.getBlkStreetUnit()); stmt.setString(11, user.getPostalCode()); stmt.executeUpdate(); return new AuthenticationResponse(true); } catch (SQLException ex) { ex.printStackTrace(); } finally { ConnectionManager.close(conn, stmt, rs); } return new AuthenticationResponse(false, "User creation failed."); }
From source file:azkaban.trigger.JdbcTriggerImplTest.java
@After public void clearDB() { try {/*from ww w . j ava2 s .co m*/ dbOperator.update("DELETE FROM triggers"); } catch (SQLException e) { e.printStackTrace(); return; } }
From source file:com.jp.systemdirector.projectzero.zab01.ap.logicbean.SZAB011CSelectLogicBean.java
public SZAB011CSelectResultData getStoringId(ContextData context, SZAB011CSelectInputData inputData) { // ????List/*w ww . ja va 2 s . co m*/ List<SZAB011CSelectDTO> resultList = new ArrayList<SZAB011CSelectDTO>(); if (context != null) { SZAB011CSelectDTO zDto = new SZAB011CSelectDTO(); // try { resultList = dao.selectStoringId(zDto); } catch (SQLException e) { e.printStackTrace(); throw new RuntimeException(e); } } // DTO?ContextData????PR??? List<ContextData> contextDataList = new ArrayList<ContextData>(); for (SZAB011CSelectDTO zSelectDTO : resultList) { if (zSelectDTO == null) { break; } ContextData contextData = new ContextData(); try { contextData.setStoringId(zSelectDTO.getSTORING_ID()); contextDataList.add(contextData); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } // ?ListMemberResultData?memberList?? SZAB011CSelectResultData resultData = new SZAB011CSelectResultData(); resultData.setResultList(contextDataList); return resultData; }
From source file:com.oic.event.GetProfile.java
@Override public void ActionEvent(JSONObject json, WebSocketListener webSocket) { JSONObject responseJSON = new JSONObject(); if (!validation(json)) { responseJSON.put("status", "1"); webSocket.sendJson(responseJSON); return;/*w w w . j ava 2 s . c om*/ } Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { String sql = "SELECT user.userid, name, avatarid, grade, sex, birth, comment, privategrade, privatesex, privatebirth FROM user JOIN setting ON (user.userid = setting.userid) WHERE user.userid = ?;"; con = DatabaseConnection.getConnection(); ps = con.prepareStatement(sql); ps.setLong(1, Long.parseLong(json.get("userid").toString())); rs = ps.executeQuery(); if (rs.next()) { responseJSON.put("userid", rs.getLong("userid")); responseJSON.put("username", rs.getString("name")); responseJSON.put("avatarid", rs.getInt("avatarid")); if (rs.getString("privategrade").equals("public")) { responseJSON.put("grade", rs.getInt("grade")); } if (rs.getString("privatesex").equals("public")) { responseJSON.put("gender", OicGender.getGender(rs.getString("sex")).toString()); } if (rs.getString("privatebirth").equals("public")) { responseJSON.put("birthday", Tools.convertData(rs.getDate("birth"))); } responseJSON.put("comment", rs.getString("comment")); responseJSON.put("status", 0); } else { responseJSON.put("status", 1); } } catch (SQLException se) { responseJSON.put("status", 1); se.printStackTrace(); } finally { try { rs.close(); } catch (Exception e1) { } try { ps.close(); } catch (Exception e1) { } } webSocket.sendJson(responseJSON); }
From source file:edu.ku.brc.specify.toycode.mexconabio.AgentNames.java
/** * @param oldDBName//from w ww . j av a2 s. c om * @param newDBName */ public AgentNames(String oldDBName, String newDBName) { super(); this.oldDBName = oldDBName; this.newDBName = newDBName; try { oldDBConn = DriverManager.getConnection(String.format(connStr, oldDBName), "root", "root"); newDBConn = DriverManager.getConnection(String.format(connStr, newDBName), "root", "root"); } catch (SQLException e) { e.printStackTrace(); } }
From source file:com.abixen.platform.service.businessintelligence.multivisualisation.application.service.JsonFilterService.java
private Map<String, String> getColumnTypeMapping(ResultSetMetaData rsmd) throws SQLException { int columnCount = rsmd.getColumnCount(); Map<String, String> columnTypeMapping = new HashMap<>(); IntStream.range(1, columnCount + 1).forEach(i -> { try {//from w ww .j a v a 2 s. c om String columnTypeName = rsmd.getColumnTypeName(i); if ("BIGINT".equalsIgnoreCase(columnTypeName)) { columnTypeName = "INTEGER"; } if ("VARCHAR".equalsIgnoreCase(columnTypeName)) { columnTypeName = "STRING"; } if ("FLOAT8".equalsIgnoreCase(columnTypeName)) { columnTypeName = "DOUBLE"; } if ("INT8".equalsIgnoreCase(columnTypeName)) { columnTypeName = "INTEGER"; } columnTypeMapping.put(rsmd.getColumnName(i).toUpperCase(), columnTypeName.toUpperCase()); } catch (SQLException e) { e.printStackTrace(); } }); return columnTypeMapping; }
From source file:com.jp.systemdirector.projectzero.zab01.ap.logicbean.SZAB011CSelectLogicBean.java
@Transactional public SZAB011CSelectResultData execute(ContextData context, SZAB011CSelectInputData inputData) { // ????List//from w w w . j a v a 2 s . com List<SZAB011CSelectDTO> resultList = new ArrayList<SZAB011CSelectDTO>(); if (context != null) { SZAB011CSelectDTO zDto = new SZAB011CSelectDTO(); zDto.setIN1(context.getProductCd()); // try { resultList = dao.findById(zDto); } catch (SQLException e) { e.printStackTrace(); throw new RuntimeException(e); } } // DTO?ContextData????PR??? List<ContextData> contextDataList = new ArrayList<ContextData>(); for (SZAB011CSelectDTO zSelectDTO : resultList) { if (zSelectDTO == null) { break; } ContextData contextData = new ContextData(); try { contextData.setProductCd(zSelectDTO.getIN1()); contextData.setQuantity(zSelectDTO.getQUANTITY().toString()); contextData.setModifyCount(zSelectDTO.getMODIFY_COUNT()); contextData.setUpdatedDate(zSelectDTO.getUPDATED_DATE()); contextDataList.add(contextData); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } // ?ListMemberResultData?memberList?? SZAB011CSelectResultData resultData = new SZAB011CSelectResultData(); resultData.setResultList(contextDataList); return resultData; }
From source file:json.UserController.java
@RequestMapping(value = "/authenticateUserService", method = RequestMethod.POST, produces = "application/json") public @ResponseBody AuthenticationResponse authenticateUser(@RequestBody LoginInput loginInput) { Connection conn = null;// w ww. ja va 2 s . co m PreparedStatement stmt = null; ResultSet rs = null; String errors = null; String query = "select userPassword from user where username = ?"; /*if(loginInput.getUsername().equals("") || loginInput.getPassword().equals("")){ errors.add("Please fill in all fields."); }*/ try { //Set up connection with database conn = ConnectionManager.getConnection(); stmt = conn.prepareStatement(query); //set username stmt.setString(1, loginInput.getUsername()); //Execute sql satatement to obtain account from database rs = stmt.executeQuery(); while (rs != null && rs.next()) { String password = rs.getString(1); if (password.equals(loginInput.getPassword())) { return new AuthenticationResponse(true); } else { errors = "Login failed. Please try again."; } } } catch (SQLException ex) { ex.printStackTrace(); } finally { ConnectionManager.close(conn, stmt, rs); } return new AuthenticationResponse(false, errors); }