List of usage examples for java.lang ClassNotFoundException getMessage
public String getMessage()
From source file:rems.Global.java
public static void runSalesInvoice(String outputUsd, String outfileName, String jsprReportPath, String reportTitle, String rptSQL) { //String reportPath = "C:/1_DESIGNS/MYAPPS/REMSProcessRunner/reports/jasper2.jrxml"; try {//from w w w . jav a 2 s. co m //Compile jrxml file. //System.out.println("Inside Jasper"); //System.in.read(); String orgNm = Global.getOrgName(Global.UsrsOrg_ID).replace("\r\n", " ").replace("\r", " ") .replace("\n", " "); String pstl = Global.getOrgPstlAddrs(Global.UsrsOrg_ID).replace("\r\n", " ").replace("\r", " ") .replace("\n", " "); //Contacts Nos String cntcts = Global.getOrgContactNos(Global.UsrsOrg_ID).replace("\r\n", " ").replace("\r", " ") .replace("\n", " "); //Email Address String email = Global.getOrgEmailAddrs(Global.UsrsOrg_ID).replace("\r\n", " ").replace("\r", " ") .replace("\n", " "); String website = Global.getOrgWebsite(Global.UsrsOrg_ID).replace("\r\n", " ").replace("\r", " ") .replace("\n", " "); String online = ""; if (!email.trim().equals("")) { online += "Email: " + email; if (!website.equals("")) { online += " Website: " + website; } } String fileName = jsprReportPath; File theFile = new File(fileName); JasperDesign jasperDesign = JRXmlLoader.load(theFile); JRDesignBand band = new JRDesignBand(); band.setHeight(90); JRDesignImage image = new JRDesignImage(jasperDesign); image.setX(1); image.setY(0); image.setHeight(70); image.setWidth(70); JRDesignExpression expression = new JRDesignExpression(); //expression.setValueClass(java.lang.String.class); //C:/Users/richard.adjei-mensah/JaspersoftWorkspace/MyReports/1.png expression.setText("$P{ImageUrl}"); image.setExpression(expression); band.addElement(image); JRDesignStaticText staticText = new JRDesignStaticText(); staticText.setX(90); staticText.setY(2); staticText.setWidth(465); staticText.setHeight(15); //staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); staticText.setText(orgNm); band.addElement(staticText); staticText = new JRDesignStaticText(); staticText.setX(90); staticText.setY(16); staticText.setWidth(465); staticText.setHeight(15); //staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); staticText.setText(pstl); band.addElement(staticText); staticText = new JRDesignStaticText(); staticText.setX(90); staticText.setY(30); staticText.setWidth(465); staticText.setHeight(15); //staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); staticText.setText(cntcts); band.addElement(staticText); staticText = new JRDesignStaticText(); staticText.setX(90); staticText.setY(45); staticText.setWidth(465); staticText.setHeight(15); //staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER); staticText.setText(online); band.addElement(staticText); staticText = new JRDesignStaticText(); staticText.setX(0); staticText.setY(73); staticText.setWidth(555); staticText.setHeight(15); staticText.setBold(true); staticText.setFontName("Arial"); staticText.setUnderline(false); staticText.setFontSize(12F); staticText.setForecolor(Color.BLUE); staticText.setHorizontalTextAlign(HorizontalTextAlignEnum.CENTER); staticText.setText(reportTitle); band.addElement(staticText); JRDesignLine nwLine = new JRDesignLine(); nwLine.setX(0); nwLine.setY(72); nwLine.setWidth(555); nwLine.setHeight(0); band.addElement(nwLine); nwLine = new JRDesignLine(); nwLine.setX(0); nwLine.setY(88); nwLine.setWidth(555); nwLine.setHeight(0); band.addElement(nwLine); jasperDesign.setTitle(band);//setPageHeader //Build a new query //rptSQL String theQuery = "SELECT * FROM org.org_details WHERE org_name ilike '%%'"; System.out.println(rptSQL); // update the data query JRDesignQuery newQuery = new JRDesignQuery(); newQuery.setText(theQuery); jasperDesign.setQuery(newQuery); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); //JasperReport jasperReport = JasperCompileManager.compileReport(reportPath); Map<String, Object> params = new HashMap<String, Object>(); //"C:/Users/richard.adjei-mensah/JaspersoftWorkspace/MyReports/1.png" params.put("ImageUrl", Global.getOrgImgsDrctry() + "/" + String.valueOf(Global.UsrsOrg_ID) + ".png"); Connection connection; Class.forName("org.postgresql.Driver"); connection = DriverManager.getConnection( "jdbc:postgresql://" + Global.Hostnme + ":" + Global.Portnum + "/" + Global.Dbase, Global.Uname, Global.Pswd); System.out.println("Filling report..."); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection); if (outputUsd.equals("MICROSOFT EXCEL")) { JRXlsExporter xlsExporter = new JRXlsExporter(); xlsExporter.setExporterInput(new SimpleExporterInput(jasperPrint)); xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outfileName)); SimpleXlsReportConfiguration xlsReportConfiguration = new SimpleXlsReportConfiguration(); //SimpleXlsExporterConfiguration xlsExporterConfiguration = new SimpleXlsExporterConfiguration(); xlsReportConfiguration.setOnePagePerSheet(false); xlsReportConfiguration.setRemoveEmptySpaceBetweenRows(true); xlsReportConfiguration.setDetectCellType(true); xlsReportConfiguration.setWhitePageBackground(false); xlsExporter.setConfiguration(xlsReportConfiguration); xlsExporter.exportReport(); } else if (outputUsd.equals("PDF")) { JasperExportManager.exportReportToPdfFile(jasperPrint, outfileName); } else if (outputUsd.equals("HTML")) { JasperExportManager.exportReportToHtmlFile(jasperPrint, outfileName); } else if (outputUsd.equals("STANDARD")) { JasperExportManager.exportReportToPdfFile(jasperPrint, outfileName); } else if (outputUsd.equals("MICROSOFT WORD")) { JRRtfExporter rtfExporter = new JRRtfExporter(); rtfExporter.setExporterInput(new SimpleExporterInput(jasperPrint)); rtfExporter.setExporterOutput(new SimpleWriterExporterOutput(outfileName)); SimpleRtfReportConfiguration rtfReportConfiguration = new SimpleRtfReportConfiguration(); //SimpleRtfExporterConfiguration xlsExporterConfiguration = new SimpleRtfExporterConfiguration(); rtfExporter.setConfiguration(rtfReportConfiguration); rtfExporter.exportReport(); } else if (outputUsd.equals("CHARACTER SEPARATED FILE (CSV)")) { JRCsvExporter exporter = new JRCsvExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(outfileName)); SimpleCsvReportConfiguration rtfReportConfiguration = new SimpleCsvReportConfiguration(); //SimpleCsvExporterConfiguration xlsExporterConfiguration = new SimpleCsvExporterConfiguration(); exporter.setConfiguration(rtfReportConfiguration); exporter.exportReport(); } else { JasperExportManager.exportReportToPdfFile(jasperPrint, outfileName); } //JasperViewer.viewReport(jasperPrint, false); System.out.println("Opening report"); if (Desktop.isDesktopSupported()) { try { File myFile = new File(outfileName); Desktop.getDesktop().open(myFile); } catch (IOException ex) { // no application registered for PDFs } } // Runtime runTime = Runtime.getRuntime(); // Process process = runTime // .exec("C:/Users/richard.adjei-mensah/Desktop/Test1.pdf"); // // System.out.println("Closing report"); // process.destroy(); connection.close(); } catch (JRException ex) { System.out.println(ex.getMessage()); } catch (ClassNotFoundException e) { System.out.println(e.getMessage()); } catch (SQLException e) { System.out.println(e.getMessage()); } try { Thread.sleep(5000); } catch (InterruptedException e) { System.out.println(e.getMessage()); } }
From source file:com.alfaariss.oa.authentication.password.PasswordAuthenticationMethod.java
/** * Function for online authentication./* w ww .jav a2 s. co m*/ * * Authenticates the user using the configured Password handler * (JDBC, JNDI, RADIUS etc.). When Captcha is enabled the user must also * submit the supplied text in the captcha image. * @see IWebAuthenticationMethod#authenticate( * HttpServletRequest, HttpServletResponse, ISession) */ public UserEvent authenticate(HttpServletRequest oRequest, HttpServletResponse oResponse, ISession oSession) throws OAException { IUser oUser = null; String sUserPassword = null; boolean bRetries = true; int iTries = _iAllowedTries; ISessionAttributes oAttributes = null; UserEvent userEvent = null; String sUserId = null; try { oAttributes = oSession.getAttributes(); // Get retries left Integer intTries = ((Integer) oAttributes.get(PasswordAuthenticationMethod.class, _sMethodID + RETRIES_ATTRIBUTE_NAME)); //handle if (intTries == null) //First call to pwd method { //get user from session oUser = oSession.getUser(); if (oUser == null) { // If no user in session, check forced user sUserId = oSession.getForcedUserID(); if (sUserId != null) { oUser = _oUserFactory.getUser(sUserId); if (oUser == null) { throw new UserException(UserEvent.AUTHN_METHOD_NOT_SUPPORTED); } if (!oUser.isEnabled()) { throw new UserException(UserEvent.USER_DISABLED); } // Check is user is registered for password method if (!oUser.isAuthenticationRegistered(_sMethodID)) { throw new UserException(UserEvent.AUTHN_METHOD_NOT_REGISTERED); } oSession.setUser(oUser); } } else { // Check is user is registered for password method if (!oUser.isAuthenticationRegistered(_sMethodID)) { throw new UserException(UserEvent.AUTHN_METHOD_NOT_REGISTERED); } } forwardUser(oRequest, oResponse, oSession, iTries, bRetries, new Vector<Enum>()); userEvent = UserEvent.AUTHN_METHOD_IN_PROGRESS; } else { iTries = intTries.intValue(); Vector<Enum> warnings = new Vector<Enum>(); // Check if captcha is enabled and verify if a captcha is supplied. String sCaptcha = null; if (_bCaptchaEnabled) { // Get supplied captcha. sCaptcha = oRequest.getParameter(CAPTCHA); if ((sCaptcha == null) || (sCaptcha.trim().length() <= 0)) { // does not count as an attempt bRetries = false; warnings.add(Warnings.NO_CAPTCHA_SUPPLIED); } } //get user from session oUser = oSession.getUser(); if (oUser == null) { // If no user in session, get it from request sUserId = oRequest.getParameter(USERID_ATTRIBUTE_NAME); if ((sUserId == null) || sUserId.equals("")) { // do not treat as an attempt bRetries = false; warnings.add(Warnings.NO_USERNAME_SUPPLIED); } else { oUser = _oUserFactory.getUser(sUserId); } } // Get supplied password. sUserPassword = oRequest.getParameter(PASSWORD); if ((sUserPassword == null) || sUserPassword.trim().equalsIgnoreCase("")) { // does not count as an attempt bRetries = false; warnings.add(Warnings.NO_PASSWORD_SUPPLIED); } //Check for missing request parameters if (!warnings.isEmpty()) { //throw new DetailedUserException(warnings); throw new DetailedUserException(UserEvent.AUTHN_METHOD_IN_PROGRESS, warnings); } //Verify captcha if (_bCaptchaEnabled) { Class cCaptchaEngine = null; try { cCaptchaEngine = Class.forName("com.alfaariss.oa.helper.captcha.engine.CaptchaEngine"); } catch (ClassNotFoundException e) { _logger.error( "Captcha enabled, but 'com.alfaariss.oa.helper.captcha.engine.CaptchaEngine' is not available", e); throw new OAException(SystemErrors.ERROR_INTERNAL); } byte[] baCaptchaHash = (byte[]) oAttributes.get(cCaptchaEngine, CAPTCHA_HASH); if (!verifyCaptcha(sCaptcha, baCaptchaHash)) { throw new DetailedUserException(UserEvent.AUTHN_METHOD_IN_PROGRESS, Warnings.INVALID_CAPTCHA_SUPPLIED); } oAttributes.remove(cCaptchaEngine, CAPTCHA_HASH); } //Verify User if (sUserId != null) //Submitted user { if (oUser == null) { throw new DetailedUserException(UserEvent.AUTHN_METHOD_IN_PROGRESS, Warnings.NO_SUCH_USER_FOUND); } } //Get the correct User ID to authenticate with the resource. String sAuthUserId = null; //If ID mapping is enabled, map the OA user name to the corresponding pwd username. if (_idMapper != null) { sAuthUserId = _idMapper.map(oUser.getID()); if (sAuthUserId == null) { throw new UserException(UserEvent.AUTHN_METHOD_FAILED); } } else { sAuthUserId = oUser.getID(); } // Authenticate with supplied credentials against the configured password method. if (!_oPasswordHandler.authenticate(sAuthUserId, sUserPassword)) { throw new DetailedUserException(UserEvent.AUTHN_METHOD_IN_PROGRESS, Warnings.INVALID_CREDENTIALS_SUPPLIED); } if (sUserId != null) { if (!oUser.isEnabled()) { throw new UserException(UserEvent.USER_DISABLED); } // Check is user is registered for password method if (!oUser.isAuthenticationRegistered(_sMethodID)) { throw new UserException(UserEvent.AUTHN_METHOD_NOT_REGISTERED); } } //everything Okay oSession.setUser(oUser); _eventLogger.info(new UserEventLogItem(oSession, oRequest.getRemoteAddr(), UserEvent.AUTHN_METHOD_SUCCESSFUL, this, null)); userEvent = UserEvent.AUTHN_METHOD_SUCCESSFUL; } } catch (UserException e) { userEvent = e.getEvent(); _eventLogger.info(new UserEventLogItem(oSession, oRequest.getRemoteAddr(), e.getEvent(), this, null)); } catch (DetailedUserException e) { if (iTries <= 0) { _eventLogger.info(new UserEventLogItem(oSession, oRequest.getRemoteAddr(), UserEvent.AUTHN_METHOD_FAILED, this, e.getDetails().toString())); userEvent = UserEvent.AUTHN_METHOD_FAILED; } else { //Event logging is executed in showPage //Show page once again forwardUser(oRequest, oResponse, oSession, iTries, bRetries, e.getDetails()); userEvent = e.getEvent(); } } catch (OAException e) { _eventLogger.info( new UserEventLogItem(oSession, oRequest.getRemoteAddr(), UserEvent.INTERNAL_ERROR, this, null)); //already logged to system log. throw e; } catch (Exception e) { if (oSession != null) { _eventLogger.info(new UserEventLogItem(oSession, oRequest.getRemoteAddr(), UserEvent.INTERNAL_ERROR, this, e.getMessage())); } else { _eventLogger.info(new UserEventLogItem(null, null, null, UserEvent.INTERNAL_ERROR, null, oRequest.getRemoteAddr(), null, this, e.getMessage())); } _logger.fatal("Unexpected runtime error occured: ", e); throw new OAException(SystemErrors.ERROR_INTERNAL); } return userEvent; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstMSSql.CFAstMSSqlSchema.java
public boolean connect() { final String S_ProcName = "connect"; if (cnx != null) { return (false); }/*ww w .ja v a 2 s .c om*/ if (configuration != null) { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "connect", "Could not load MS SQL Server 2012 Express Advanced Edition driver", e); } String dbServer = configuration.getDbServer(); int dbPort = configuration.getDbPort(); String dbDatabase = configuration.getDbDatabase(); String dbUserName = configuration.getDbUserName(); String dbPassword = configuration.getDbPassword(); String url = "jdbc:sqlserver://" + dbServer + ":" + Integer.toString(dbPort) + ";"; Properties props = new Properties(); props.setProperty("user", dbUserName); props.setProperty("password", dbPassword); try { cnx = DriverManager.getConnection(url, props); cnx.setAutoCommit(false); cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); cnx.rollback(); setDbSchemaName(dbDatabase); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<connect>>", e); } Statement stmtUseDatabase = null; try { stmtUseDatabase = cnx.createStatement(); stmtUseDatabase.executeUpdate("use " + dbDatabase); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<useDatabase>>", e); } finally { if (stmtUseDatabase != null) { try { stmtUseDatabase.close(); } catch (SQLException e) { } stmtUseDatabase = null; } } return (true); } if (jndiName != null) { try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup(jndiName); if (ds == null) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Could not get resolve DataSource \"" + jndiName + "\""); } cnx = ds.getConnection(); if (cnx == null) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Could not get Connection from PooledConnection for ConnectionPoolDataSource \"" + jndiName + "\""); } cnx.setAutoCommit(false); cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); cnx.rollback(); } catch (NamingException e) { cnx = null; throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName + "<<jndiGetConnection>>", "NamingException " + e.getMessage(), e); } catch (SQLException e) { cnx = null; inTransaction = false; throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<jndiGetConnection>>", e); } return (true); } throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Neither configurationFile nor jndiName found, do not know how to connect to database"); }
From source file:Sales.TabbedPaneWin.java
private void initCustom() throws Exception { ///Client//w w w .jav a2s . co m //setting next CleientID nextClientId(); clientIdTxtF2.setText(getNextClientIdStr()); //refreshing Table try { jTable3.setModel(DbUtils.resultSetToTableModel(refreshTableClient())); } catch (ClassNotFoundException ex) { Logger.getLogger(TabbedPaneWin.class.getName()).log(Level.SEVERE, null, ex); } //// ///Agreemnrt nextAgreementId(); agreementIdTxtF1.setText(getNextAgreementIdStr()); try { jTable1.setModel(DbUtils.resultSetToTableModel(OOAgreement.dispalyTableExpiary())); } catch (ClassNotFoundException ex) { Logger.getLogger(TabbedPaneWin.class.getName()).log(Level.SEVERE, null, ex);//Logiing errors System.err.println(ex.getMessage()); JOptionPane.showMessageDialog(null, ex.getMessage(), "Unknown Error", JOptionPane.ERROR_MESSAGE); } /////// ///Invoice nextInvoiceId(); invoiceNoTxtF.setText(getNextInvoiceIdStr()); incrementations.nextOrderId(); clientIdTxtF1.setText(incrementations.getNextOrderIdStr()); try { selectItemsTable.setModel(DbUtils.resultSetToTableModel(refreshTableInvoice())); } catch (ClassNotFoundException ex) { Logger.getLogger(TabbedPaneWin.class.getName()).log(Level.SEVERE, null, ex); } /// jLabel45.setVisible(false); jLabel70.setVisible(false); jLabel73.setVisible(false); jLabel72.setVisible(false); jLabel18.setVisible(false); jLabel43.setVisible(false); jLabel1.setVisible(false); jLabel44.setVisible(false); jLabel71.setVisible(false); jLabel74.setVisible(false); jLabel75.setVisible(false); jLabel67.setVisible(false); jLabel74.setVisible(false); jLabel76.setVisible(false); jLabel80.setVisible(false); jLabel79.setVisible(false); jLabel82.setVisible(false); jLabel77.setVisible(false); jLabel78.setVisible(false); jLabel81.setVisible(false); jLabel83.setVisible(false); jLabel85.setVisible(false); jLabel84.setVisible(false); //Item PIe Chart DefaultPieDataset dataSet = new DefaultPieDataset(); try { Connection con = DBAccess.getConnection(); Statement st = con.createStatement(); ResultSet rs = st.executeQuery( "Select distinct citem.item_code,citem.`type`,Sum(Invoice_Detail.saleQty) as 'Sum QTy'\n" + "from citem,Invoice_Detail\n" + "where Invoice_Detail.itemCode = citem.item_code \n" + "group by citem.item_code,citem.`type`"); while (rs.next()) { dataSet.setValue(rs.getString("type"), rs.getInt("Sum QTy")); } } catch (SQLException e) { System.err.println(e.getMessage()); } JFreeChart chart = ChartFactory.createPieChart("Products Sold by Brand", dataSet, true, true, true); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setSize(490, 376); jPanel11.add(chartPanel); jPanel11.setVisible(true); //Year Bar chart DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); try { Connection con = DBAccess.getConnection(); Statement st = con.createStatement(); ResultSet rs = st.executeQuery( "select distinct DATE_FORMAT(Invoice.`date`,'%Y')as 'Year',SUM(invoice.grandTotal)\n" + "from invoice\n" + "group by DATE_FORMAT(Invoice.`date`,'%Y')\n" + ""); while (rs.next()) { if (rs.getString("Year") != null) { dataset2.setValue(rs.getInt("SUM(invoice.grandTotal)"), rs.getString("Year"), rs.getString("Year")); } } } catch (SQLException e) { System.err.println(e.getMessage()); } JFreeChart chart2 = ChartFactory.createBarChart("Yearly Sales", "Year", "Total Sales(Rs)", dataset2, PlotOrientation.VERTICAL, true, true, true); ChartPanel chartPanel2 = new ChartPanel(chart2); chartPanel2.setSize(480, 420); jPanel18.add(chartPanel2); jPanel18.setVisible(true); //Month Bar Chart DefaultCategoryDataset dataset3 = new DefaultCategoryDataset(); try { Connection con = DBAccess.getConnection(); Statement st = con.createStatement(); ResultSet rs = st.executeQuery( "select distinct DATE_FORMAT(Invoice.`date`,'%Y-%m')as 'Month',SUM(invoice.grandTotal)\n" + "from invoice\n" + "group by DATE_FORMAT(Invoice.`date`,'%Y-%m')"); while (rs.next()) { String month = rs.getString("Month"); if (month != null) {//if no data if (String.valueOf(Calendar.getInstance().get(Calendar.YEAR)).equals(month.substring(0, 4))) { //for sum up to curet year only if ("01".equals(month.substring(5, 7))) { dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Jan", "Jan"); } else if ("02".equals(month.substring(5, 7))) { dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Feb", "Feb"); } else if ("03".equals(month.substring(5, 7))) { dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Mar", "Mar"); } else if ("04".equals(month.substring(5, 7))) { dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Apr", "Apr"); } else if ("05".equals(month.substring(5, 7))) { dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "May", "May"); } else if ("06".equals(month.substring(5, 7))) { dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Jun", "Jun"); } else if ("07".equals(month.substring(5, 7))) { dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Jul", "Jul"); } else if ("08".equals(month.substring(5, 7))) { dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Aug", "Aug"); } else if ("09".equals(month.substring(5, 7))) { dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Sep", "Sep"); } else if ("10".equals(month.substring(5, 7))) { dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Oct", "Oct"); } else if ("11".equals(month.substring(5, 7))) { dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Nov", "Nov"); } else if ("12".equals(month.substring(5, 7))) { dataset3.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Dec", "Dec"); } } } } } catch (SQLException e) { System.err.println(e.getMessage()); } JFreeChart chart3 = ChartFactory.createBarChart( "Monthly Sales of " + String.valueOf(Calendar.getInstance().get(Calendar.YEAR)), "Month", "Total Sales(Rs)", dataset3, PlotOrientation.VERTICAL, true, true, true); ChartPanel chartPanel3 = new ChartPanel(chart3); chartPanel3.setSize(480, 431); jPanel21.add(chartPanel3); jPanel21.setVisible(true); //Daily Bar Chart DefaultCategoryDataset dataset4 = new DefaultCategoryDataset(); int weekNo = 1; try { Connection con = DBAccess.getConnection(); Statement st = con.createStatement(); SimpleDateFormat newDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; ResultSet rs = st.executeQuery( "select distinct DATE_FORMAT(Invoice.`date`,'%Y-%m-%d')as 'Day',SUM(invoice.grandTotal)\n" + "from invoice\n" + "group by DATE_FORMAT(Invoice.`date`,'%Y-%m-%d')"); while (rs.next()) { String day = rs.getString("Day"); if (day != null) { if (String.valueOf(Calendar.getInstance().get(Calendar.YEAR)).equals(day.substring(0, 4))) { //for sum up to curet year only date = newDateFormat.parse(day); day = date.toString().substring(0, 3); if (day.equals("Mon")) { dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Mon", "Mon"); } else if (day.equals("Tue")) { dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Tue", "Tue"); } else if (day.equals("Wed")) { dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Wed", "Wed"); } else if (day.equals("Thu")) { dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Thu", "Thu"); } else if (day.equals("Fri")) { dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Fri", "Fri"); } else if (day.equals("Sat")) { dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Sat", "Sat"); } else if (day.equals("Sun")) { dataset4.setValue(rs.getInt("SUM(invoice.grandTotal)"), "Sun", "Sun"); } } } } } catch (SQLException e) { System.err.println(e.getMessage()); } Calendar cal = Calendar.getInstance(); JFreeChart chart4 = ChartFactory.createBarChart( "Daily Sales of " + new SimpleDateFormat("MMM").format(cal.getTime()) + " Week " + weekNo, "Day", "Total Sales(Rs)", dataset4, PlotOrientation.VERTICAL, true, true, true); ChartPanel chartPanel4 = new ChartPanel(chart4); chartPanel4.setSize(480, 431); jPanel25.add(chartPanel4); jPanel25.setVisible(true); }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java
public boolean connect() { final String S_ProcName = "connect"; if (cnx != null) { return (false); }// w ww . j ava 2 s . com if (configuration != null) { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "connect", "Could not load MS SQL Server 2012 Express Advanced Edition driver", e); } String dbServer = configuration.getDbServer(); int dbPort = configuration.getDbPort(); String dbDatabase = configuration.getDbDatabase(); String dbUserName = configuration.getDbUserName(); String dbPassword = configuration.getDbPassword(); String url = "jdbc:sqlserver://" + dbServer + ":" + Integer.toString(dbPort) + ";"; Properties props = new Properties(); props.setProperty("user", dbUserName); props.setProperty("password", dbPassword); try { cnx = DriverManager.getConnection(url, props); cnx.setAutoCommit(false); cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); cnx.rollback(); setSchemaDbName(dbDatabase); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<connect>>", e); } Statement stmtUseDatabase = null; try { stmtUseDatabase = cnx.createStatement(); stmtUseDatabase.executeUpdate("use " + dbDatabase); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<useDatabase>>", e); } finally { if (stmtUseDatabase != null) { try { stmtUseDatabase.close(); } catch (SQLException e) { } stmtUseDatabase = null; } } return (true); } if (jndiName != null) { try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup(jndiName); if (ds == null) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Could not get resolve DataSource \"" + jndiName + "\""); } cnx = ds.getConnection(); if (cnx == null) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Could not get Connection from DataSource \"" + jndiName + "\""); } cnx.setAutoCommit(false); cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); cnx.rollback(); } catch (NamingException e) { cnx = null; throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName + "<<jndiGetConnection>>", "NamingException " + e.getMessage(), e); } catch (SQLException e) { cnx = null; inTransaction = false; throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<jndiGetConnection>>", e); } return (true); } throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Neither configurationFile nor jndiName found, do not know how to connect to database"); }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_1.CFAstSybase.CFAstSybaseSchema.java
public boolean connect() { final String S_ProcName = "connect"; if (cnx != null) { return (false); }// w ww. ja v a 2 s . c o m if (configuration != null) { try { Class.forName("com.sybase.jdbc4.jdbc.SybDriver"); } catch (ClassNotFoundException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), "connect", "Could not load Sybase ASE 15.7 driver", e); } String dbServer = configuration.getDbServer(); int dbPort = configuration.getDbPort(); String dbDatabase = configuration.getDbDatabase(); String dbUserName = configuration.getDbUserName(); String dbPassword = configuration.getDbPassword(); String url = "jdbc:sybase:Tds:" + dbServer + ":" + Integer.toString(dbPort); Properties props = new Properties(); props.setProperty("user", dbUserName); props.setProperty("password", dbPassword); try { cnx = DriverManager.getConnection(url, props); cnx.setAutoCommit(false); cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); cnx.rollback(); setDbSchemaName(dbDatabase); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<connect>>", e); } Statement stmtUseDatabase = null; try { stmtUseDatabase = cnx.createStatement(); stmtUseDatabase.executeUpdate("use " + dbDatabase); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<useDatabase>>", e); } finally { if (stmtUseDatabase != null) { try { stmtUseDatabase.close(); } catch (SQLException e) { } stmtUseDatabase = null; } } Statement stmtSetChainedOff = null; try { stmtSetChainedOff = cnx.createStatement(); stmtSetChainedOff.executeUpdate("set chained off"); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<setChainedOff>>", e); } finally { if (stmtSetChainedOff != null) { try { stmtSetChainedOff.close(); } catch (SQLException e) { } stmtSetChainedOff = null; } } return (true); } if (jndiName != null) { try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup(jndiName); if (ds == null) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Could not get resolve DataSource \"" + jndiName + "\""); } cnx = ds.getConnection(); if (cnx == null) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Could not get Connection from PooledConnection for ConnectionPoolDataSource \"" + jndiName + "\""); } cnx.setAutoCommit(false); cnx.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); cnx.rollback(); } catch (NamingException e) { cnx = null; throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName + "<<jndiGetConnection>>", "NamingException " + e.getMessage(), e); } catch (SQLException e) { cnx = null; inTransaction = false; throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName + "<<jndiGetConnection>>", e); } return (true); } throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Neither configurationFile nor jndiName found, do not know how to connect to database"); }
From source file:de.innovationgate.wgpublisher.WGACore.java
public WGDatabase retrievePersonalisationDB(Domain domainConfig) throws WGAServerException { PersonalisationDatabase config = domainConfig.getPersonalisation(); // Get basic information String strType = config.getImplClassName(); // Look if impl class is reachable Class<WGDatabaseCore> typeClass; try {// w w w . j av a 2 s . c o m Class theClass = Class.forName(strType, true, WGFactory.getImplementationLoader()); if (!WGDatabaseCore.class.isAssignableFrom(theClass)) { throw new WGAServerException("Cannot connect personalisation database for domain \"" + domainConfig.toString() + "\" - Database implementation class \"" + strType + "\" is no WGDatabaseCore implementation."); } typeClass = theClass; } catch (ClassNotFoundException e) { throw new WGAServerException( "Cannot attach personalisation database to domain \"" + domainConfig.toString() + "\" - Database implementation class \"" + strType + "\" not available."); } catch (NoClassDefFoundError e) { throw new WGAServerException("Cannot attach personalisation database to domain \"" + domainConfig.toString() + "\" - Database implementation class or dependent class for type \"" + strType + "\" not found: \"" + e.getMessage()); } catch (VerifyError e) { log.error("Cannot attach personalisation database to domain \"" + domainConfig.toString() + "\" - Verify error: " + e.getMessage()); return null; } // Retrieve server WGDatabaseServer server = getDatabaseServers().get(config.getDbServer()); if (server == null) { throw Problem.create(new UpdateConfigOccasion(), new DomainScope(domainConfig.getName()), "updateConfigProblem.domainPersServerUnknown", ProblemSeverity.HIGH, Problem.var("serverid", config.getDbServer())); } // Merge db options from global, server, database HashMap<String, String> dbOptions = new HashMap<String, String>(); putDefaultDbOptions(dbOptions); dbOptions.putAll(_wgaConfiguration.getGlobalDatabaseOptions()); dbOptions.putAll(server.getOptions()); dbOptions.putAll(config.getDatabaseOptions()); // Mandatory db options dbOptions.put(WGDatabase.COPTION_DBREFERENCE, "personalisation_" + domainConfig.getUid()); // get the database object WGDatabase db = null; try { if (config.isLazyConnecting()) { db = server.prepareDatabase(typeClass, dbOptions); } else { db = server.openDatabase(typeClass, dbOptions); } } catch (WGAPIException e) { throw new WGAServerException("Could not connect to database", e); } catch (ModuleDependencyException e) { throw new WGAServerException( "Could not connect to database because of missing dependency: " + e.getMessage()); } if (db == null) { throw new WGAServerException("Could not open personalisation database for domain '" + domainConfig.getName() + " - Check logged messages above for error details"); } else if (!db.getRoles().contains(WGDatabase.ROLE_USERPROFILES)) { throw new WGAServerException("Could not open personalisation database \for domain '" + domainConfig.getName() + " - This type does not deliver user profiles"); } if (config.isLazyConnecting()) { log.info("Preparing personalisation database on path \"" + db.getPath() + "\" for domain \"" + domainConfig.getName() + "\""); db.addDatabaseConnectListener(this); } else { log.info("Attaching personalisation database on path \"" + db.getPath() + "\" to domain \"" + domainConfig.getName() + "\""); try { log.info("Personalisation database of domain " + domainConfig.getName() + " is content store version " + db.getContentStoreVersion()); } catch (WGAPIException e) { throw new WGAServerException( "Exception determining content store version of personalisation database for domain " + domainConfig.getName(), e); } } // Set domain db.setAttribute(WGACore.DBATTRIB_DOMAIN, domainConfig.getUid()); // Mark this database as fully connected db.setAttribute(DBATTRIB_FULLY_CONNECTED, "true"); return db; }
From source file:de.innovationgate.webgate.api.WGDatabase.java
private void createDBCoreObject(String strType) throws WGInvalidDatabaseException { Class dbClass;//from w ww . jav a 2 s. co m try { dbClass = Class.forName(strType, true, WGFactory.getImplementationLoader()); if (!WGDatabaseCore.class.isAssignableFrom(dbClass)) { throw new WGInvalidDatabaseException("Cannot allocate db type " + strType + ": is no implementation of " + WGDatabaseCore.class.getName()); } this.core = (WGDatabaseCore) dbClass.newInstance(); } catch (ClassNotFoundException exc) { throw new WGInvalidDatabaseException( "Database implementation class or dependent class not found. Check classpath: " + exc.getMessage()); } catch (NoClassDefFoundError err) { throw new WGInvalidDatabaseException( "Database implementation class or dependent class not found. Check classpath: " + err.getMessage()); } catch (IllegalAccessException exc) { throw new WGInvalidDatabaseException( "Database implementation class or dependent class not accessible: " + exc.getMessage()); } catch (InstantiationException exc) { throw new WGInvalidDatabaseException("Could not instantiate implementation class: " + exc.getMessage()); } }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public static Connection openConnect(String url, String user, String pass) throws SQLException, MetaStoreConnectException { try {/* w w w . java2 s. c om*/ Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException e) { LOG.error(" get org.postgresql.Driver failed "); e.printStackTrace(); throw new MetaStoreConnectException(e.getMessage()); } Connection conn = null; DriverManager.setLoginTimeout(timeout); // DriverManager.setLoginTimeout(10); conn = DriverManager.getConnection(url, user, pass); LOG.debug(" get Connection ok: " + url); return conn; }