List of usage examples for java.sql SQLException printStackTrace
public void printStackTrace()
From source file:com.chiorichan.account.adapter.sql.SqlAdapter.java
@Override public void failedLoginUpdate(AccountMetaData meta, LoginExceptionReason reason) { try {/*from w ww. jav a2 s .c o m*/ sql.queryUpdate("UPDATE `" + table + "` SET `lastActive` = '" + Common.getEpoch() + "', `lastLoginFail` = 0, `numLoginFail` = 0 WHERE `acctID` = '" + meta.getAcctId() + "'"); } catch (SQLException e) { e.printStackTrace(); } meta.set("lastActive", Common.getEpoch()); meta.set("lastLoginFail", 0); meta.set("numLoginFail", 0); }
From source file:json.UserController.java
@RequestMapping(value = "/getUsersService", method = RequestMethod.GET, produces = "application/json") public @ResponseBody ArrayList<User> getUsers() { Connection conn = null;// w ww . java 2 s .com Statement stmt = null; ResultSet rs = null; ArrayList<User> userList = new ArrayList(); try { //Set up connection with database conn = ConnectionManager.getConnection(); stmt = conn.createStatement(); //Execute sql satatement to obtain account from database rs = stmt.executeQuery("select * from user;"); while (rs != null && rs.next()) { String username = rs.getString(1); String password = rs.getString(2); String emailAddress = rs.getString(3); String fullname = rs.getString(4); String contactNo = rs.getString(5); String nricType = rs.getString(6); String nric = rs.getString(7); String dob = rs.getString(8); String gender = rs.getString(9); String blkStreetUnit = rs.getString(10); String postalCode = rs.getString(11); userList.add(new User(username, password, emailAddress, fullname, contactNo, nricType, nric, dob, gender, blkStreetUnit, postalCode)); } } catch (SQLException ex) { ex.printStackTrace(); } finally { ConnectionManager.close(conn, stmt, rs); } return userList; }
From source file:com.spfsolutions.ioms.auth.UserAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { try {//from www . ja va 2 s .c o m UserEntity userEntity = userDao.queryForFirst( userDao.queryBuilder().where().eq("Username", authentication.getName()).prepare()); String inputHash = MD5.encrypt(authentication.getCredentials().toString()); if (userEntity == null || !userEntity.getPassword().equals(inputHash)) { throw new BadCredentialsException("Username or password incorrect."); } else if (!userEntity.isEnabled()) { throw new DisabledException("The username is disabled. Please contact your System Administrator."); } userEntity.setLastSuccessfulLogon(new DateTime(DateTimeZone.UTC).toDate()); userDao.createOrUpdate(userEntity); Collection<SimpleGrantedAuthority> authorities = buildRolesFromUser(userEntity); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( authentication.getName(), authentication.getCredentials(), authorities); return token; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { userDao.getConnectionSource().closeQuietly(); } return null; }
From source file:edu.isi.karma.webserver.ExtractSpatialInformationFromWikimapiaServiceHandler.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("Request URL: " + request.getRequestURI()); logger.debug("Request Path Info: " + request.getPathInfo()); logger.debug("Request Param: " + request.getQueryString()); String jsonOutput = null;// w w w .j av a 2 s . c o m String lon_min = request.getParameter("lon_min"); String lat_min = request.getParameter("lat_min"); String lon_max = request.getParameter("lon_max"); String lat_max = request.getParameter("lat_max"); //String type = request.getParameter("type"); String url = "&lon_min=" + lon_min + "&lat_min=" + lat_min + "&lon_max=" + lon_max + "&lat_max=" + lat_max; try { System.out.println("Please Wait for extracting information from Web Site..."); outputToOSM(url); System.out.println("You have got the OSM File at location: /tmp/GET_WIKIMAPIA.xml ..."); } catch (SQLException e) { e.printStackTrace(); } System.out.println("Opening PostGis Connection..."); openConnection(); System.out.println("Creating the CSV file from OSM file..."); CreateWikimapiaInformation cwi = new CreateWikimapiaInformation(this.connection, this.osmFile_path); System.out.println("Extracting the Street Information from OSM file..."); jsonOutput = cwi.createWikiMapiaTable(); System.out.println("You have created the CSV file for STREETS at location:/tmp/buildings_geo.csv"); /*Close connection*/ this.closeConnection(this.connection); /*Output the JSON content to Web Page*/ response.setCharacterEncoding("UTF8"); PrintWriter pw = response.getWriter(); response.setContentType(MimeType.APPLICATION_JSON); pw.write(jsonOutput); return; }
From source file:jlp.aspectj.test.MainDBCPAndC3P0test.java
public void run() { while (running) { Connection con = null;// w w w .ja v a2s. co m Statement stmt = null; ResultSet rs = null; Connection con1 = null; Statement stmt1 = null; ResultSet rs1 = null; try { con = bds.getConnection(); stmt = con.createStatement(); rs = stmt.executeQuery("SELECT * FROM javatest.testdata"); con1 = cpds.getConnection(); stmt1 = con1.createStatement(); rs1 = stmt1.executeQuery("SELECT * FROM javatest.testdata"); Thread.sleep(100); // while (rs.next()) // System.out.println(rs.getString(1)); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { // i try to be neurotic about ResourceManagement, // explicitly closing each resource // but if you are in the habit of only closing // parent resources (e.g. the Connection) and // letting them close their children, all // c3p0 DataSources will properly deal. attemptClose(rs); attemptClose(stmt); attemptClose(con); attemptClose(rs1); attemptClose(stmt1); attemptClose(con1); } } }
From source file:org.mule.modules.basicauthsecurity.strategy.JDBCSecurityProvider.java
/** * Are we connected/*from w w w.jav a2 s. com*/ */ @ValidateConnection public boolean isConnected() { if (managerDataSource == null) { return false; } try { Boolean result = managerDataSource.getConnection().isValid(1000); return result; } catch (SQLException e) { e.printStackTrace(); return false; } }
From source file:org.projecthdata.ehr.viewer.service.WeightSyncService.java
@Override protected void onHandleIntent(Intent intent) { this.editor = prefs.edit(); editor.putString(Constants.PREF_WEIGHT_SYNC_STATE, SyncState.WORKING.toString()).commit(); try {// w w w. j a v a 2 s . com Dao<RootEntry, Integer> rootDao = hDataOrmManager.getDatabaseHelper().getRootEntryDao(); Dao<SectionDocMetadata, Integer> sectionDao = hDataOrmManager.getDatabaseHelper() .getSectionDocMetadataDao(); // find the first entry that has the right schema and contains xml // documents RootEntry entry = rootDao.queryForFirst( rootDao.queryBuilder().where().eq(RootEntry.COLUMN_NAME_EXTENSION, Constants.EXTENSION_RESULT) .and().like(RootEntry.COLUMN_PATH, "%bodyweight%").and() .eq(RootEntry.COLUMN_NAME_CONTENT_TYPE, MediaType.APPLICATION_XML).prepare()); List<SectionDocMetadata> metadatas = sectionDao .query(sectionDao.queryBuilder().where().eq("rootEntry_id", entry.get_id()).and() .eq("contentType", MediaType.APPLICATION_XML).prepare()); // grab that document and parse out the patient info Connection<HData> connection = connectionRepository.getPrimaryConnection(HData.class); RestTemplate restTemplate = connection.getApi().getRootOperations().getRestTemplate(); Dao<WeightReading, Integer> weightDao = ehrDatabaseHelper.getWeightReadingDao(); //delete all entries in the table weightDao.delete(weightDao.deleteBuilder().prepare()); //add new entries to the table for (SectionDocMetadata metadata : metadatas) { Result result = restTemplate.getForObject(metadata.getLink(), Result.class); // copy result into a WeightReading an persist it WeightReading weight = new WeightReading(); weight.copy(result); weightDao.create(weight); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } editor.putString(Constants.PREF_WEIGHT_SYNC_STATE, SyncState.READY.toString()).commit(); }
From source file:com.anyuan.thomweboss.persistence.JdbcTest.java
public void testConnJdbc() { BasicDataSource datSource = new BasicDataSource(); datSource.setDriverClassName("org.postgresql.Driver"); datSource.setUrl("jdbc:postgresql://127.0.0.1:5432/thomdb"); datSource.setUsername("thomoss"); datSource.setPassword("ossthom"); try {//from w w w . ja v a 2 s . c om datSource.getConnection(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } JdbcTemplate jdbcTemplate = new JdbcTemplate(datSource); }
From source file:com.eventbook.controller.SpringbootPocController.java
@RequestMapping(value = "/mySQLTest", method = RequestMethod.GET) public String mySQLTest() { java.sql.Connection conn = null; Statement stmt = null;//from ww w . j a va2s. co m try { Class.forName(JDBC_DRIVER); conn = DriverManager.getConnection(DB_URL, USER, PASS); stmt = conn.createStatement(); String sql = "SELECT User FROM user"; ResultSet rs = stmt.executeQuery(sql); StringBuilder response = new StringBuilder(""); while (rs.next()) { String user = rs.getString("User"); response.append("\nUser: " + user); System.out.print("\nUser: " + user); } rs.close(); stmt.close(); conn.close(); return response.toString(); } catch (SQLException se) { se.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (stmt != null) { stmt.close(); } if (conn != null) { conn.close(); } } catch (SQLException se) { se.printStackTrace(); } } return "mySQLTest has been failed!!"; }
From source file:org.projecthdata.ehr.viewer.service.PatientSyncService.java
private void doSyncPatientInfo() { this.editor = prefs.edit(); editor.putString(Constants.PREF_PATIENT_INFO_SYNC_STATE, SyncState.WORKING.toString()).commit(); try {/*from w ww.java 2 s. c o m*/ Dao<RootEntry, Integer> rootDao = hDataOrmManager.getDatabaseHelper().getRootEntryDao(); Dao<SectionDocMetadata, Integer> sectionDao = hDataOrmManager.getDatabaseHelper() .getSectionDocMetadataDao(); // find the first entry that has the right schema and contains xml documents RootEntry entry = rootDao.queryForFirst( rootDao.queryBuilder().where().eq(RootEntry.COLUMN_NAME_EXTENSION, Constants.EXTENSION_PATIENT) .and().eq(RootEntry.COLUMN_NAME_CONTENT_TYPE, MediaType.APPLICATION_XML).prepare()); //find the metadata for the first xml document in the section owned by the previous found root entry SectionDocMetadata metadata = sectionDao .queryForFirst(sectionDao.queryBuilder().where().eq("rootEntry_id", entry.get_id()).and() .eq("contentType", MediaType.APPLICATION_XML).prepare()); // grab that document and parse out the patient info Connection<HData> connection = connectionRepository.getPrimaryConnection(HData.class); RestTemplate restTemplate = connection.getApi().getRootOperations().getRestTemplate(); Patient patientInfo = restTemplate.getForObject(metadata.getLink(), Patient.class); save(patientInfo); //get the url for their photo entry = rootDao.queryForFirst( rootDao.queryBuilder().where().eq(RootEntry.COLUMN_NAME_EXTENSION, Constants.EXTENSION_PNG) .and().eq(RootEntry.COLUMN_NAME_CONTENT_TYPE, MediaType.IMAGE_PNG).prepare()); if (entry != null) { metadata = sectionDao.queryForFirst(sectionDao.queryBuilder().where() .eq("rootEntry_id", entry.get_id()).and().eq("contentType", MediaType.IMAGE_PNG).prepare()); this.editor.putString(Constants.PREF_PATIENT_PHOTO_URL, metadata.getLink()); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } this.editor.putString(Constants.PREF_PATIENT_INFO_SYNC_STATE, SyncState.READY.toString()); //committing all of the changes this.editor.commit(); }