List of usage examples for java.sql SQLException printStackTrace
public void printStackTrace()
From source file:com.hx.sync.service.ThreadCallBackTask.java
public void writeLog(DatabaseUtil dest, TmOvLog log) { String sql = " insert into tm_ov_log (sync_type,key_data,sync_log,log_time,sync_status,entity_code,data_node) values (?,?,?,?,?,?,?);"; List<Object> params = new ArrayList<Object>(); params.add(log.getSyncType());//from w ww . java 2s.c o m params.add(log.getKeyData()); params.add(log.getSyncLog()); params.add(DateUtil.getCurrentTimestamp()); params.add(log.getSyncStatus()); params.add(log.getEntityCode()); params.add(log.getDataNode()); Connection conn = dest.getConn(); PreparedStatement ps = null; try { ps = conn.prepareStatement(sql); for (int i = 0; i < params.size(); i++) { ps.setObject(i + 1, params.get(i)); } ps.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (ps != null) { try { ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:com.concentricsky.android.khanacademy.util.CaptionManager.java
private List<Caption> persist(final List<Caption> toSave, final String youtubeId) { try {/*from w w w . j a v a 2s.c o m*/ final Dao<Caption, Integer> captionDao = dataService.getHelper().getDao(Caption.class); if (captionDao != null && toSave != null && toSave.size() > 0) { // Batching speeds this up significantly. captionDao.callBatchTasks(new Callable<Void>() { @Override public Void call() throws Exception { for (Caption c : toSave) { try { c.setYoutube_id(youtubeId); captionDao.create(c); } catch (SQLException e) { e.printStackTrace(); } } return null; } }); } } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return toSave; }
From source file:net.xqx.controller.web.QyzzController.java
/** * ??/*from ww w . j a v a 2 s. c om*/ * * @param request * @return */ @RequestMapping("showCompany") public String showCompany(HttpServletRequest request) { PageDao pageDao = new PageDao(); String id = request.getParameter("id"); ResultSet rs = null; Connection conn = null; PreparedStatement statement = null; if (id != null && !"".equals(id)) { try { conn = pageDao.getAptitudeConnection(); String sql = "select c.fCompanyName,c.fCompanyType,c.fRightMan,r.fCapital,r.fPaiclUpCapital,r.fRegLicenseNo," + "cer.fCertificateLevel,cer.fCertificateNo,c.fOperatingDate,cer.fCertifyDate," + "cer.fValidBeginDate,cer.fValidEndDate,c.fAddress,c.fDetails,c.fCompanyId from TCompanyInfo c left join TCertificate cer " + "on c.fCompanyId=cer.fCompanyId left join TRegInfo r " + "on c.fCompanyId=r.fCompanyInfoId where c.fCompanyId=?"; statement = conn.prepareStatement(sql); statement.setInt(1, Integer.parseInt(id)); rs = statement.executeQuery(); TCompanyInfo companyInfo = null; if (rs != null) { while (rs.next()) { companyInfo = new TCompanyInfo(); companyInfo.setfCompanyName(rs.getString(1)); companyInfo.setfCompanyType(rs.getString(2)); companyInfo.setfRightMan(rs.getString(3)); companyInfo.setfCapitals(rs.getString(4)); companyInfo.setfCapitalsUp(rs.getString(5)); companyInfo.setfLicenseNo(rs.getString(6)); companyInfo.setfCertificateLevel(rs.getString(7)); companyInfo.setfCertificateNo(rs.getString(8)); companyInfo.setfOperatingDate(rs.getString(9)); companyInfo.setfCertificateDate(rs.getString(10)); companyInfo.setfCertificateBeginDate(rs.getString(11)); companyInfo.setfCertificateEndDate(rs.getString(12)); companyInfo.setfRegAddress(rs.getString(13)); companyInfo.setfDetails(rs.getString(14)); companyInfo.setfCompanyId(rs.getInt(15)); } } request.setAttribute("companyInfo", companyInfo); rs.close(); statement.close(); conn.close(); } catch (SQLException e) { System.out.println("!"); e.printStackTrace(); } finally { pageDao.closeConnection(rs, statement, conn); } } return "web/showCompany"; }
From source file:org.esupportail.dining.web.controllers.ViewController.java
@RequestMapping("/favorite/add") public String setFavorite(@RequestParam(value = "id", required = true) String id) throws Exception { User user = this.authenticator.getUser(); try {//from w w w. j a v a 2s. c o m this.dc.executeUpdate( "INSERT INTO FAVORITERESTAURANT VALUES ('" + StringEscapeUtils.escapeSql(user.getLogin()) + "', '" + StringEscapeUtils.escapeSql(id) + "');"); } catch (SQLException e) { e.printStackTrace(); } catch (NullPointerException e) { /* * Useful is the user isn't logged * in */ } return "redirect:/restaurant?id=" + id; }
From source file:com.mycompany.barbershop.Appointment.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . j a va 2 s.c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String JDBC_DRIVER = "com.mysql.jdbc.Driver"; String DB_URL = null; // Detect if we are on openshift or local environment. String db_host = System.getenv("OPENSHIFT_MYSQL_DB_HOST"); if (db_host != null) { String db_port = System.getenv("OPENSHIFT_MYSQL_DB_PORT"); DB_URL = "jdbc:mysql://" + db_host + ":" + db_port + "/barbershop"; } else { DB_URL = "jdbc:mysql://127.0.0.1/barbershop"; } String USER = "admint7Jze9t"; String PASS = "5kkJlvZVANR9"; Connection conn = null; Statement stmt = null; try { //STEP 2: Register JDBC driver Class.forName("com.mysql.jdbc.Driver"); //STEP 3: Open a connection conn = DriverManager.getConnection(DB_URL, USER, PASS); //STEP 4: Execute a query stmt = conn.createStatement(); //Query to get barber id int barber_id = 0; String barber_name = (String) request.getParameter("barber"); String sql = "SELECT * FROM barber_table WHERE name = '" + barber_name + "';"; ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { barber_id = rs.getInt("barber_id"); } String day = (String) request.getParameter("day"); String time = (String) request.getParameter("time"); String type = (String) request.getParameter("type"); String user_id = (String) request.getSession().getAttribute("user_id"); //Check to see if an appointent is already made for that barber at that time sql = "select * from appointment_table where barber_id ='" + barber_id + "' and start_time ='" + time + "' and date ='" + day + "';"; rs = stmt.executeQuery(sql); if (rs.next()) { request.setAttribute("appointmentError", "Scheduling conflict. Please schedule another time"); request.getRequestDispatcher("/home.jsp").forward(request, response); } else { sql = "INSERT INTO appointment_table(barber_id, user_id, start_time, date)" + "VALUES (" + barber_id + ", " + user_id + ", '" + time + "', '" + day + "')"; } stmt.executeUpdate(sql); HttpSession session = request.getSession(false); String name = (String) session.getAttribute("name"); request.setAttribute("appointmentMessage", "Appointment successfully created for " + name + " with " + barber_name + " for a " + type + " at " + time + " on " + day); //TEXTING API // String firstName = (String) request.getSession().getAttribute("name"); // request.setAttribute("appointmentMessage", "Appointment successfully created for " + firstName + " with " + barber_name + " for a " + type + " at " + time + " on " + day); // // // String phonenum = ""; // sql = "SELECT * FROM user_table WHERE firstName='" + firstName + "';"; // rs = stmt.executeQuery(sql); // while (rs.next()) { // phonenum = rs.getString("phone"); // } // // TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN); // // // Build a filter for the MessageList // List<NameValuePair> params = new ArrayList<>(); // params.add(new BasicNameValuePair("Body", "Thank you for choosing Graffitti! " // + "Your next appointment will be on " + day + " at " + time + ".")); // params.add(new BasicNameValuePair("To", "+1" + phonenum)); // params.add(new BasicNameValuePair("From", "+19784345321")); // // MessageFactory messageFactory = client.getAccount().getMessageFactory(); // Message message = messageFactory.create(params); request.getRequestDispatcher("/home.jsp").forward(request, response); } 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) { conn.close(); } } catch (SQLException se) { } // do nothing try { if (conn != null) { conn.close(); } } catch (SQLException se) { se.printStackTrace(); } //end finally try } //end try }
From source file:com.extrahardmode.module.MsgPersistModule.java
/** * Set the count of a certain message to a certain value * * @param node node to set the count for * @param playerId player for whom we are tracking the count * @param value value to set/*from w ww . ja va2 s .c o m*/ */ private void set(MessageNode node, int playerId, int value) { Validate.isTrue(value >= 0, "Count has to be positive"); Connection conn = null; Statement statement = null; try { conn = retrieveConnection(); statement = conn.createStatement(); //Set the count to the provided value String setQuery = String.format("UPDATE %s SET %s = %s WHERE id = %s", msgTable, node.getColumnName(), value, playerId); statement.execute(setQuery); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (conn != null) conn.close(); if (statement != null) statement.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:jmdbtools.JMdbTools.java
private void exportToMySQL() { try {/*from w w w . j a va2 s . co m*/ System.out.println(dbName); Connection conn = connectToMySQL(dbName, dbUsername, dbPassword); DbSchema tableSet = createDbSchema(); createTables(tableSet, conn); insertAllData(tableSet, conn); } catch (SQLException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } finally { //finally block used to close resources //conn.close(); } }
From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet2.java
/** * Returns a sample dataset./* w w w . j ava 2s . co m*/ * * @return The dataset. */ private CategoryDataset createDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Calendar calendarEnd = Calendar.getInstance(); int tzoffset = calendarEnd.getTimeZone().getOffset(calendarEnd.getTimeInMillis()); long timeEnd = calendarEnd.getTimeInMillis(); timeEnd = timeEnd - (timeEnd % (60 * 60 * 24 * 1000)) - tzoffset; calendarEnd.setTimeInMillis(timeEnd); try { Connection connection = Util.getConnection("main", getServletContext()); Calendar calendarBegin = (Calendar) calendarEnd.clone(); calendarBegin.add(Calendar.DAY_OF_MONTH, -7); getMetrics(connection, "", "CLIENT_CONNECTIONS", calendarBegin, calendarEnd, dataset); getMetrics(connection, "", "CLIENT_CONNECTIONS", calendarBegin, calendarEnd, dataset); } catch (SQLException e) { logger.error(e); e.printStackTrace(); } // result.addValue(20.3, "product 1 (US)", "01.01.2010"); // result.addValue(27.2, "product 1 (US)", "02.01.2010"); // result.addValue(19.7, "product 1 (US)", "03.01.2010"); // result.addValue(19.7, "product 1 (US)", "04.01.2010"); // result.addValue(19.7, "product 1 (US)", "05.01.2010"); // result.addValue(19.7, "product 1 (US)", "06.01.2010"); // result.addValue(19.7, "product 1 (US)", "07.01.2010"); // // result.addValue(19.4, "product 1 (Europe)", "01.01.2010"); // result.addValue(10.9, "product 1 (Europe)", "02.01.2010"); // result.addValue(18.4, "product 1 (Europe)", "03.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "04.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "05.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "06.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "07.01.2010"); return dataset; }
From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet2.java
/** * Returns a sample dataset.//w ww . j ava 2 s. c o m * * @return The dataset. */ private CategoryDataset createDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Calendar calendarEnd = Calendar.getInstance(); int tzoffset = calendarEnd.getTimeZone().getOffset(calendarEnd.getTimeInMillis()); long timeEnd = calendarEnd.getTimeInMillis(); timeEnd = timeEnd - (timeEnd % (60 * 60 * 24 * 1000)) - tzoffset; calendarEnd.setTimeInMillis(timeEnd); try { Connection connection = Util.getConnection("main", getServletContext()); Calendar calendarBegin = (Calendar) calendarEnd.clone(); calendarBegin.add(Calendar.DAY_OF_MONTH, -7); getMetrics(connection, "??? (DCM-)", "ALL_DCM_SIZE", calendarBegin, calendarEnd, dataset); getMetrics(connection, "? (JPG-)", "ALL_IMAGE_SIZE", calendarBegin, calendarEnd, dataset); } catch (SQLException e) { logger.error(e); e.printStackTrace(); } // result.addValue(20.3, "product 1 (US)", "01.01.2010"); // result.addValue(27.2, "product 1 (US)", "02.01.2010"); // result.addValue(19.7, "product 1 (US)", "03.01.2010"); // result.addValue(19.7, "product 1 (US)", "04.01.2010"); // result.addValue(19.7, "product 1 (US)", "05.01.2010"); // result.addValue(19.7, "product 1 (US)", "06.01.2010"); // result.addValue(19.7, "product 1 (US)", "07.01.2010"); // // result.addValue(19.4, "product 1 (Europe)", "01.01.2010"); // result.addValue(10.9, "product 1 (Europe)", "02.01.2010"); // result.addValue(18.4, "product 1 (Europe)", "03.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "04.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "05.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "06.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "07.01.2010"); return dataset; }
From source file:shell.framework.organization.role.service.impl.TblSysRoleService4JdbcImpl.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public Map<Object, Object> findFunctionByRoleID(TblSysRoleVO sysRoleVO) { Map resultMap = new HashMap(); List<?> funcAllList = new ArrayList(); try {// ww w . j ava 2 s . c o m //???? funcAllList = MPTTTreeUtil.retrieveAllTree(SystemParam.AUTHORITY_TREE_ROOT_ID, this.jdbcBaseDao); } catch (SQLException e) { e.printStackTrace(); } String sql = "select ID,FUNCTION_NAME from TBL_SYS_FUNCTION , TBL_SYS_AUTHORITY where ID=FUNCTION_ID and ROLE_ID ='" + sysRoleVO.getRole().getId() + "'"; List<?> funcList = jdbcBaseDao.query(sql); List funcOfRoleList = new ArrayList(); for (Object funcMap : funcList) { if (funcMap instanceof Map) { TblSysFunction funcVO = new TblSysFunction(); Map functionMap = (HashMap) funcMap; funcVO.setId(functionMap.get("ID").toString()); funcVO.setFunctionName(functionMap.get("FUNCTION_NAME").toString()); funcOfRoleList.add(funcVO); } } resultMap.put("funcAllList", funcAllList); resultMap.put("funcOfRoleList", funcOfRoleList); return resultMap; }