List of usage examples for java.sql SQLException printStackTrace
public void printStackTrace()
From source file:edu.ku.brc.specify.toycode.mexconabio.AgentNames.java
/** * /*from ww w. j a v a2 s .c o m*/ */ protected void findBadAgents() { Connection dbConn = null; try { Vector<String> names = getDatabases(); System.out.println("-------------- Bad Agent Databases ------------------"); for (String dbName : names) { dbConn = DriverManager.getConnection(String.format(connStr, dbName), "root", "root"); //System.out.println("-> "+dbName); String sql = "SELECT COUNT(*) FROM agent WHERE LastName IS NOT NULL AND (LastName LIKE '%;%' OR LastName LIKE '%,%')"; int cnt = BasicSQLUtils.getCountAsInt(dbConn, sql); if (cnt > 1) { System.out.println(dbName + " " + cnt); if (cnt > 1) { sql = "SELECT LastName, FirstName, MiddleInitial FROM agent WHERE LastName IS NOT NULL AND (LastName LIKE '%;%' OR LastName LIKE '%,%') LIMIT 0,10"; for (Object[] row : BasicSQLUtils.query(dbConn, sql)) { String lastName = (String) row[0]; String firstName = (String) row[1]; String middleInit = (String) row[1]; lastName = StringUtils.replaceChars(lastName, '\n', ' '); System.out.println(" [" + lastName + "][" + (firstName == null ? "" : firstName) + "][" + (middleInit == null ? "" : middleInit) + "]"); parseForNames(lastName); } } } dbConn.close(); } } catch (SQLException e) { e.printStackTrace(); } }
From source file:com.pivotal.gfxd.demo.services.PredictionService.java
/** * Return the predicted load for a given timestamp and time slice. The * slice determines the time window into which the timestamp will fall. * * @param timestamp timestamp in seconds * @param interval/*from w ww . j a va 2 s .c om*/ * @return the predicted load */ public float predictedLoad(long timestamp, TimeSlice.Interval interval) { float median = 0; float currentLoad = 0; TimeSlice slice = new TimeSlice(timestamp, interval); TimeSlice sliceNext = slice.shift(1); TimeSlice slicePast = slice.shift(-1); try { float[] lastDays = new float[3]; // Find the average for the last 3 days for (int i = 1; i < 4; i++) { // Weekdays start at 1 so subtract 1 in order to be able to do modulo // arithmetic. Then add 1 at the end again. int pastDay = (sliceNext.getWeekday() - 1 - i) % 7; // Also, java modulo arithmetic returns negative if the dividend is negative if (pastDay < 0) { pastDay += 7; } pastDay += 1; lastDays[i - 1] = getHistoricalAverageLoad(pastDay, sliceNext.getIntervalStart(), sliceNext.getIntervalEnd()); } median = median(lastDays); currentLoad = getCurrentAverageLoad(slicePast.getWeekday(), slicePast.getIntervalStart(), slicePast.getIntervalEnd()); } catch (SQLException e) { e.printStackTrace(); } return (median + currentLoad) / 2; }
From source file:com.zousu.mongopresser.MySQLHandler.java
public void initialiseDatabase() { try {// w ww . j a va 2s . c om tableList = retrieveTables(); for (int i = 0; i < tableList.size(); i++) { Table table = tableList.get(i); fillColumnsForTable(table); // print it out table.printColumns(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.sun.portal.os.portlets.ChartServlet.java
private JFreeChart createChart(HttpServletRequest request) { JFreeChart chart = null;// w w w . ja va 2 s. com try { HttpSession session = request.getSession(true); PortletPreferences prefs = (PortletPreferences) session.getAttribute("PORTLET_PREFERENCES"); if (prefs == null) throw new NoPreferredDbSetException("Preferences not passed in from portlet"); String type = prefs.getValue(Constants.PREF_CHART_TYPE, PIE_CHART); debugMessage("Chart type :" + type); if (type.equals(PIE_CHART)) { String sql = prefs.getValue(Constants.PREF_PIE_CHART_SQL, DEFAULT_PIE_CHART_SQL); PieDataset data = (PieDataset) generatePieDataSet(getDatabaseConnection(request), sql); chart = ChartFactory.createPieChart("Pie Chart", data, true, true, false); } else if (type.equals(BAR_CHART)) { String sql = prefs.getValue(Constants.PREF_BAR_CHART_SQL, DEFAULT_BAR_CHART_SQL); JDBCCategoryDataset data = (JDBCCategoryDataset) generateBarChartDataSet( getDatabaseConnection(request), sql); chart = ChartFactory.createBarChart3D("Bar Chart", "Category", "Value", data, PlotOrientation.VERTICAL, true, true, false); } else if (type.equals(TIME_CHART)) { String sql = prefs.getValue(Constants.PREF_TIME_SERIES_SQL, DEFAULT_TIME_SERIES_SQL); JDBCXYDataset data = (JDBCXYDataset) generateXYDataSet(getDatabaseConnection(request), sql); chart = ChartFactory.createTimeSeriesChart("Time Series Chart", "Date", "Rate", data, true, true, false); } } catch (NoPreferredDbSetException npdbs) { npdbs.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return chart; }
From source file:json.ApplicantController.java
@RequestMapping(value = "/createJobApplication", method = RequestMethod.POST, produces = "application/json") public @ResponseBody AuthenticationResponse createJobApplication(@RequestBody Applicant applicant) { Connection conn = null;// ww w .ja va 2 s . com PreparedStatement stmt = null; ResultSet rs = null; DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); Date date = new Date(); String currDate = dateFormat.format(date).toString(); String query = "INSERT INTO application (jobIDApplied, username, dateApplied, status) VALUES (?,?,?,?)"; System.out.println("user" + query); try { //Set up connection with database conn = ConnectionManager.getConnection(); stmt = conn.prepareStatement(query); stmt.setInt(1, applicant.getJobIDApplied()); stmt.setString(2, applicant.getUsername()); stmt.setString(3, currDate); stmt.setString(4, "Pending"); stmt.executeUpdate(); return new AuthenticationResponse(true); } catch (SQLException ex) { ex.printStackTrace(); } finally { ConnectionManager.close(conn, stmt, rs); } return new AuthenticationResponse(false, "Application creation failed."); }
From source file:com.foxelbox.foxbukkit.database.DatabaseConnectionPool.java
private DatabaseConnectionPool() { try {/*from w ww . j a va 2 s . c o m*/ Class.forName("com.mysql.jdbc.Driver"); } catch (Exception e) { System.err.println("Error loading JBBC MySQL: " + e.toString()); } GenericObjectPool connectionPool = new GenericObjectPool(null); connectionPool.setMaxActive(10); connectionPool.setMaxIdle(5); connectionPool.setTestOnBorrow(true); connectionPool.setTestOnReturn(true); connectionPool.setTestWhileIdle(true); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( FoxBukkit.instance.configuration.getValue("database-uri", "jdbc:mysql://localhost:3306/foxbukkit_database"), FoxBukkit.instance.configuration.getValue("database-user", "root"), FoxBukkit.instance.configuration.getValue("database-password", "password")); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, new StackKeyedObjectPoolFactory(), "SELECT 1", false, true); poolableConnectionFactory.setValidationQueryTimeout(3); dataSource = new PoolingDataSource(connectionPool); try { initialize(); } catch (SQLException exc) { System.err.println("Error initializing MySQL Database"); exc.printStackTrace(); } }
From source file:com.naver.timetable.jdbc.CubridDataManager.java
public Connection getConnection() { try {//from ww w . j a va 2 s . co m return dataSource.getConnection(); } catch (SQLException e) { e.printStackTrace(); return null; } }
From source file:com.iucosoft.eavertizare.dao.impl.FirmaDaoImpl.java
@Override public void dropTableClients(String tableName) { try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement();) { String queryLocal = "DROP TABLE " + tableName; stmt.executeUpdate(queryLocal);/* ww w . ja v a 2 s .co m*/ } catch (SQLException e) { e.printStackTrace(); } }
From source file:ca.fastenalcompany.jsonconfig.ProductJson.java
public int update(String query, String... params) { Connection conn = null;//from www .j a v 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 rowsEffect = pstmt.executeUpdate(); ResultSet rs = pstmt.getGeneratedKeys(); if (rs.next()) { result = rs.getInt(1); } else if (rowsEffect > 0) { result = Integer.parseInt(params[params.length - 1]); } } catch (SQLException ex) { ex.printStackTrace(); } finally { try { System.out.println(PropertyManager.getProperty("db_conn_closed")); if (conn != null) { conn.close(); } } catch (SQLException ex) { ex.printStackTrace(); } } return result; }
From source file:ca.fastenalcompany.jsonconfig.ProductJson.java
/** * Produces a basic JSON Object using the JSON Object API * * @return - The JSON Object// w w w .j av a 2 s . c o m */ public JSONArray query(String query, String... params) { Connection conn = null; 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 label = rs.getMetaData().getColumnLabel(i); String value = rs.getString(label); product.put(label, value); } products.add(product); } } catch (SQLException ex) { ex.printStackTrace(); } finally { try { System.out.println(PropertyManager.getProperty("db_conn_closed")); if (conn != null) { conn.close(); } } catch (SQLException ex) { ex.printStackTrace(); } } return products; }