List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:it.grid.storm.persistence.util.db.DBConnectionPool.java
private void handleSQLException(SQLException e) throws PersistenceException { log.error("SQL Error: {}, SQLState: {}, VendorError: {}.", e.getMessage(), e.getSQLState(), e.getErrorCode(), e);//from w w w. j a va 2 s . c o m throw new PersistenceException(e); }
From source file:Login.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Login</title>"); out.println("</head>"); out.println("<body>"); HttpSession session = request.getSession(); Connection connection = (Connection) session.getAttribute("connection"); if (connection == null) { String userName = request.getParameter("username"); String password = request.getParameter("password"); if (userName == null || password == null) { // prompt the user for her username and password out.println("<form method=\"get\" action=\"Login\">"); out.println("Please specify the following to log in:<p>"); out.println("Username: <input type=\"text\" " + "name=\"username\" size=\"30\"><p>"); out.println("Password: <input type=\"password\" " + "name=\"password\" size=\"30\"><p>"); out.println("<input type=\"submit\" value=\"Login\">"); out.println("</form>"); } else {/*from w w w .ja v a 2 s. com*/ // create the connection try { connection = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", userName, password); } catch (SQLException e) { out.println("Login doGet() " + e.getMessage()); } if (connection != null) { // store the connection session.setAttribute("connection", connection); response.sendRedirect("Login"); return; } } } else { String logout = request.getParameter("logout"); if (logout == null) { // test the connection Statement statement = null; ResultSet resultSet = null; String userName = null; try { statement = connection.createStatement(); resultSet = statement.executeQuery("select initcap(user) from sys.dual"); if (resultSet.next()) userName = resultSet.getString(1); } catch (SQLException e) { out.println("Login doGet() SQLException: " + e.getMessage() + "<p>"); } finally { if (resultSet != null) try { resultSet.close(); } catch (SQLException ignore) { } if (statement != null) try { statement.close(); } catch (SQLException ignore) { } } out.println("Hello " + userName + "!<p>"); out.println("Your session ID is " + session.getId() + "<p>"); out.println("It was created on " + new java.util.Date(session.getCreationTime()) + "<p>"); out.println("It was last accessed on " + new java.util.Date(session.getLastAccessedTime()) + "<p>"); out.println("<form method=\"get\" action=\"Login\">"); out.println("<input type=\"submit\" name=\"logout\" " + "value=\"Logout\">"); out.println("</form>"); } else { // close the connection and remove it from the session try { connection.close(); } catch (SQLException ignore) { } session.removeAttribute("connection"); out.println("You have been logged out."); } } out.println("</body>"); out.println("</html>"); }
From source file:de.klemp.middleware.controller.Controller.java
@GET @Path("/start") public static synchronized String start() { PropertyConfigurator.configure("log4j.properties"); String ok = "ok"; isBrokerStarted();/*from w w w. ja v a 2s . co m*/ controllerToList(); ActiveDevicesToList(); deviceActive.put("VLCPlayerIntern,----------------", true); createDBConnection(); try { PreparedStatement st = conn.prepareStatement( "insert into \"OutputDevices\"(class,topic,enabled) values ('VLCPlayer','----------------','t');"); st.execute(); } catch (SQLException e) { String message = e.getMessage(); if (!message.contains("doppelter Schlsselwert")) { logger.error("SQL Exception", e); } } closeDBConnection(); return ok; }
From source file:com.pontecultural.flashcards.WebServicesController.java
/** * Fetch cards for deck. /* w w w . j a va 2 s. co m*/ */ @RequestMapping(value = "/deckId/{deckId}/cards.json", method = RequestMethod.GET) public String getCards(HttpServletRequest req, @PathVariable Integer deckId, Model model) { logger.info("get cards for deck: " + deckId); try { model.addAttribute("flashcards", jdbcFlashcardsDao.fetchCardsByDeck(deckId)); } catch (DataAccessException e) { SQLException sqle = (SQLException) e.getCause(); logger.error("Error code: " + sqle.getErrorCode()); logger.error("SQL state: " + sqle.getSQLState()); logger.error("Error msg: " + sqle.getMessage()); model.addAttribute("flashcards", null); } return "flashcardstemplate"; // was "observationtemplate" - do I need to configure this someone? }
From source file:org.cloudfoundry.community.servicebroker.postgresql.service.PostgreSQLServiceInstanceService.java
@Override public DeleteServiceInstanceResponse deleteServiceInstance( DeleteServiceInstanceRequest deleteServiceInstanceRequest) throws ServiceBrokerException { String serviceInstanceId = deleteServiceInstanceRequest.getServiceInstanceId(); ServiceInstance instance = getServiceInstance(serviceInstanceId); try {/*from w w w . j a va2s . c om*/ dbAdmin.deleteDatabase(serviceInstanceId); role.deleteRole(serviceInstanceId); } catch (SQLException e) { logger.error("Error while deleting service instance '" + serviceInstanceId + "'", e); throw new ServiceBrokerException(e.getMessage()); } repos.delete(serviceInstanceId); return new DeleteServiceInstanceResponse(); }
From source file:database.DataBaseMySQL.java
public ResultSet get(String[] keys, String t_name) { ResultSet res;//from ww w .j a v a2s . c om Statement stmt; String query = "select "; for (int i = 0; i < keys.length; i++) { query = query + keys[i] + " ,"; } query = query.replace(query.substring(query.length() - 1), ""); query = query + "from " + t_name; System.out.println(query); try { stmt = conn.createStatement(); res = stmt.executeQuery(query); return res; /* while (res.next()) { int id = res.getInt("id"); String title = res.getString("title"); System.out.println("Get value from kay's :"+title); } */ // Now do something with the ResultSet .... } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } return res = null; }
From source file:com.nextep.designer.sqlgen.model.base.AbstractCapturer.java
@Override public void initialize(IConnection conn, IMutableCaptureContext context) { final IConnectionService connectionService = CorePlugin.getConnectionService(); final IDatabaseConnector<?> connector = connectionService.getDatabaseConnector(conn); try {//w ww.ja v a 2 s.c om Connection jdbcConn = connectionService.connect(conn); context.setConnectionObject(jdbcConn); context.setSchema(connector.getSchema(conn)); context.setCatalog(connector.getCatalog(conn)); context.setConnection(conn); } catch (SQLException sqle) { throw new ErrorException( "Unable to connect to the " + conn.getDBVendor() + " database: " + sqle.getMessage(), sqle); } }
From source file:com.wso2telco.dep.reportingservice.dao.WorkflowDAO.java
/** * Update subscription tier.//from w w w . jav a2 s. co m * * @param subscriptionId the subscription id * @param tierId the tier id * @throws Exception */ public void updateSubscriptionTier(String subscriptionId, String tierId) throws Exception { Connection conn = null; ResultSet rs = null; PreparedStatement ps = null; try { conn = DbUtils.getDbConnection(DataSourceNames.WSO2AM_DB); String query = "UPDATE AM_SUBSCRIPTION SET TIER_ID=?" + " WHERE SUBSCRIPTION_ID=?"; ps = conn.prepareStatement(query); ps.setString(1, tierId); ps.setInt(2, Integer.parseInt(subscriptionId)); ps.executeUpdate(); } catch (SQLException e) { handleException("Error in updating subscription tier : " + e.getMessage(), e); } finally { DbUtils.closeAllConnections(ps, conn, rs); } }
From source file:com.wso2telco.dep.reportingservice.dao.WorkflowDAO.java
/** * Update application tier.// w w w. j a v a 2 s . co m * * @param applicationId the application id * @param tierId the tier id * @throws Exception */ public void updateApplicationTier(String applicationId, String tierId) throws Exception { Connection conn = null; ResultSet rs = null; PreparedStatement ps = null; try { conn = DbUtils.getDbConnection(DataSourceNames.WSO2AM_DB); String query = "UPDATE " + ReportingTable.AM_APPLICATION + " SET APPLICATION_TIER=?" + " WHERE APPLICATION_ID=?"; ps = conn.prepareStatement(query); ps.setString(1, tierId); ps.setInt(2, Integer.parseInt(applicationId)); ps.executeUpdate(); } catch (SQLException e) { handleException("Error in updating application tier : " + e.getMessage(), e); } finally { DbUtils.closeAllConnections(ps, conn, rs); } }
From source file:fuel.gui.stats.StationStatsPanel.java
private void refreshGraphs() { graphContainer.removeAll();/*from w w w . j a va 2 s. com*/ DefaultPieDataset usageDataset = new DefaultPieDataset(); try { for (Station station : database.getStations()) { ResultSet thisStation = database .Query("SELECT SUM(liter) FROM fuelrecords WHERE stationId = " + station.getId(), true); thisStation.next(); usageDataset.setValue(station.toString(), thisStation.getInt("1")); } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause()); } JFreeChart usagePieChart = ChartFactory.createPieChart3D("", usageDataset, true, true, false); PiePlot3D plot3 = (PiePlot3D) usagePieChart.getPlot(); plot3.setForegroundAlpha(0.6f); //plot3.setCircular(true); JPanel usagePieChartPanel = new ChartPanel(usagePieChart); usagePieChartPanel.setBorder( BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Tankstation verhouding"))); usagePieChartPanel.setPreferredSize(new java.awt.Dimension(320, 240)); DefaultPieDataset fuelDataset = new DefaultPieDataset(); try { ResultSet numberResults = database.Query("SELECT DISTINCT typeOfGas FROM fuelrecords", true); while (numberResults.next()) { ResultSet thisStation = database.Query("SELECT SUM(liter) FROM fuelrecords WHERE typeOfGas = '" + numberResults.getString("typeOfGas") + "'", true); thisStation.next(); fuelDataset.setValue(numberResults.getString("typeOfGas"), thisStation.getInt("1")); } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause()); } JFreeChart fuelPieChart = ChartFactory.createPieChart3D("", fuelDataset, true, true, false); PiePlot3D plot2 = (PiePlot3D) fuelPieChart.getPlot(); plot2.setForegroundAlpha(0.6f); //plot3.setCircular(true); JPanel fuelPieChartPanel = new ChartPanel(fuelPieChart); fuelPieChartPanel.setBorder( BorderFactory.createTitledBorder(BorderFactory.createTitledBorder("Brandstof verhouding"))); fuelPieChartPanel.setPreferredSize(new java.awt.Dimension(320, 240)); DefaultCategoryDataset barDataset = new DefaultCategoryDataset(); try { ResultSet motorThing = database.Query("SELECT cost/liter,date FROM fuelrecords ORDER BY date ASC", true); while (motorThing.next()) { barDataset.addValue(motorThing.getDouble("1"), motorThing.getString("date"), "Prijs per liter"); } } catch (SQLException ex) { JOptionPane.showMessageDialog(null, ex.getMessage() + ex.getCause()); } JFreeChart barChart = ChartFactory.createBarChart3D("", // chart title "", // domain axis label "Aantal", // range axis label barDataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips? false // URLs? ); CategoryPlot plot = barChart.getCategoryPlot(); BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer(); renderer.setDrawBarOutline(false); ChartPanel barChartPanel = new ChartPanel(barChart); barChartPanel.getChartRenderingInfo().setEntityCollection(null); barChartPanel.setBorder(BorderFactory.createTitledBorder("Prijs per liter")); barChartPanel.setPreferredSize(new java.awt.Dimension(320, 240)); JPanel piePanel = new JPanel(new GridLayout(0, 2)); piePanel.add(usagePieChartPanel); piePanel.add(fuelPieChartPanel); graphContainer.add(piePanel); graphContainer.add(barChartPanel); revalidate(); repaint(); }