private void ListValueChanged( javax.swing.event.ListSelectionEvent evt) { // GEN-FIRST:event_ListValueChanged // TODO add your handling code here: // String part=partno.getText(); try { String sql = "SELECT TYPE,ITEM_NAME,QUANTITY,MRP FROM MOTORS WHERE ITEM_NAME='" + List.getSelectedValue() + "'"; Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", ""); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { partno.setText(rs.getString("TYPE")); name.setText(rs.getString("ITEM_NAME")); qty.setText(rs.getString("QUANTITY")); rate.setText(rs.getString("MRP")); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e.toString()); } } // GEN-LAST:event_ListValueChanged
private void jButton3ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton3ActionPerformed try { Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", ""); Statement stmt = con.createStatement(); ResultSet resultSet = stmt.executeQuery("select Bill_No from bill;"); String productCode = null; while (resultSet.next()) { productCode = resultSet.getString("Bill_No"); } int pc = Integer.parseInt(productCode); System.out.println(pc); no.setText((String.valueOf(++pc))); // TODO add your handling code here: String part = partno.getText(); String itemname = name.getText(); String qty1 = qty.getText(); String rate1 = rate.getText(); // String amo=amount.getText(); String noo = no.getText(); no1 = Integer.parseInt(noo); cname = custname.getText(); bill1 = bill.getText(); addr1 = addr.getText(); String ta = tax.getText(); int a = Integer.parseInt(qty1); int b = Integer.parseInt(rate1); int c = a * b; String str = Integer.toString(c); amount.setText(str); String str1 = amount.getText(); /* String sql1="select Quantity from lubricants"; String sql2="UPDATE LUBRICANTS SET QUANTITY=QUANTITY-qty1 WHERE PART_NO='"+partno+"'"; Statement stmt1=con.createStatement(); ResultSet rs1= stmt1.executeQuery(sql1); String ch=rs1.getString("QUANTITY"); int q=Integer.parseInt(qty1); int r=Integer.parseInt(ch); if(q >r) { JOptionPane.showMessageDialog(this,"STOCK UNAVAILABLE"); } else { stmt1.executeUpdate(sql2); }*/ } catch (SQLException ex) { Logger.getLogger(Billspare.class.getName()).log(Level.SEVERE, null, ex); } } // GEN-LAST:event_jButton3ActionPerformed
private void jButton4ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: String wash = chrg.getText(); cname = custname.getText(); addr1 = addr.getText(); total.setText(String.valueOf(tamount)); String a = lcharge.getText(); String b = total.getText(); String j = la.getText(); String c = con.getText(); int d = Integer.parseInt(b); int e = Integer.parseInt(a); int g = Integer.parseInt(wash); int h = Integer.parseInt(c); int i = Integer.parseInt(j); int f = d + e + g + h + i; toamnt.setText(String.valueOf(f)); String sql = "insert into bill(Bill_No,Bill_Date,Cust_Name,Cust_Addr,P_Details,Amount) values('" + no1 + "','" + bill1 + "','" + cname + "','" + addr1 + "','" + pd + "','" + toamnt + "')"; try { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", ""); Statement stmt = con.createStatement(); stmt.executeUpdate(sql); } catch (Exception e2) { JOptionPane.showMessageDialog(this, e2.getMessage()); } } // GEN-LAST:event_jButton4ActionPerformed
public void FillList() { try { String sql1 = "select * from motors"; Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", ""); Statement stmt = con.createStatement(); ResultSet rs1 = stmt.executeQuery(sql1); DefaultListModel DLM = new DefaultListModel(); while (rs1.next()) { DLM.addElement(rs1.getString(3)); // DLM.addElement(rs1.getString(2)); } List.setModel(DLM); } catch (Exception e) { JOptionPane.showMessageDialog(null, "e.getString()"); } }
private void jButton1ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: String part = partno.getText(); String itemname = name.getText(); String qty1 = qty.getText(); String rate1 = rate.getText(); String no1 = no.getText(); String cname = custname.getText(); String bill1 = bill.getText(); String addr1 = addr.getText(); String ta = tax.getText(); String str1 = amount.getText(); DefaultTableModel model = (DefaultTableModel) Table.getModel(); model.addRow( new Object[] { (String.valueOf(++i)), partno.getText(), name.getText(), tax.getText(), qty.getText(), rate.getText(), amount.getText() }); pd = pd + "," + "(" + part + "," + itemname + "," + qty1 + ")"; tamount = tamount + Integer.parseInt(str1); try { Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", ""); Statement stmt2 = con.createStatement(); stmt2.executeUpdate( "UPDATE MOTORS SET QUANTITY=QUANTITY-'" + qty1 + "' WHERE ITEM_NAME='" + part + "'"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.toString()); } } // GEN-LAST:event_jButton1ActionPerformed
/** * Takes a vector full of property lists and generates a report. * * @param args Command line arguments. args[0] should be the config filename. */ public static void main(String[] args) { // Load the database properties from properties file Properties properties = new Properties(); // Load config file String configFile = null; if (args.length > 0) configFile = args[0]; try { if (configFile == null) { System.out.println("Database config file not set."); return; } else properties.load(new FileInputStream(configFile)); } catch (IOException e) { System.out.println("Error opening config file."); } String url = properties.getProperty("databaseUrl"); String username = properties.getProperty("username"); String password = properties.getProperty("password"); String dir = System.getProperty("user.dir"); // Current working directory Connection con = null; // Try to open file containing javac output String output = ""; try { BufferedReader outputReader = new BufferedReader(new FileReader(dir + "/CompileOut.txt")); while (outputReader.ready()) output += outputReader.readLine() + '\n'; // Close file outputReader.close(); } catch (FileNotFoundException e) { System.out.println("Error opening compilation output file."); return; } catch (IOException e) { System.out.println("I/O Exception Occured."); return; } boolean hasDriver = false; // Create class for the driver try { Class.forName("com.mysql.jdbc.Driver"); hasDriver = true; } catch (Exception e) { System.out.println("Failed to load MySQL JDBC driver class."); } // Create connection to database if the driver was found if (hasDriver) { try { con = DriverManager.getConnection(url, username, password); } catch (SQLException e) { System.out.println("Couldn't get connection!"); } } // Check that a connection was made if (con != null) { long userEventId = -1; // Store results from the report into the database try { BufferedReader rd = new BufferedReader( new FileReader(dir + "/userId.txt")); // Read userId.txt to get userId String userId = rd.readLine(); // Store userId from text file rd.close(); // Insert the report into the table and get the auto_increment id for it Statement stmt = con.createStatement(); stmt.executeUpdate("INSERT INTO userEvents (userId) VALUES ('" + userId + "')"); ResultSet result = stmt.getGeneratedKeys(); result.next(); userEventId = result.getLong(1); // Close the statement stmt.close(); // Prepare statement for adding the compilation error to the userEvent PreparedStatement compErrorPrepStmt = con.prepareStatement( "INSERT INTO userEventCompilationErrors(userEventId, output) VALUES (?, ?)"); // Insert userEventId and docletId into the database compErrorPrepStmt.setLong(1, userEventId); compErrorPrepStmt.setString(2, output); compErrorPrepStmt.executeUpdate(); // Close the prepare statements compErrorPrepStmt.close(); } catch (Exception e) { System.out.println("Exception Occurred"); System.out.println(e); } // Store the java files for the report try { // Prepare statement for storing files PreparedStatement filePrepStmt = con.prepareStatement( "INSERT INTO files(userEventId, filename, contents) VALUES (" + userEventId + ", ?, ?)"); // Get the list of files from source.txt BufferedReader rd = new BufferedReader( new FileReader(dir + "/source.txt")); // Read userId.txt to get userId while (rd.ready()) { String filename = rd.readLine(); // Store userId from text file // Remove the "src/" from the beginning to get the real file name String realname = filename.substring(4); filePrepStmt.setString(1, realname); // Read in the contents of the files String contents = ""; File javaFile = new File(dir + "/" + filename); int length = (int) javaFile.length(); // Add parameter for file contents to the prepared statement and execute it filePrepStmt.setCharacterStream(2, new BufferedReader(new FileReader(javaFile)), length); filePrepStmt.executeUpdate(); } rd.close(); } catch (IOException e) { System.err.println("I/O Exception Occured."); } catch (SQLException e) { System.err.println("SQL Exception Occured."); } } }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html;charset=UTF-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; _jspx_resourceInjector = (org.glassfish.jsp.api.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("\n"); out.write("<!DOCTYPE html>\n"); out.write("<html>\n"); out.write(" <head>\n"); out.write( " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n"); out.write(" <title>Fine</title>\n"); out.write(" <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"> \n"); out.write("\n"); out.write(" </head>\n"); out.write(" <body style = \"background-image: url(lib2.jpg)\"> \n"); out.write(" <center>\n"); out.write(" <h1>Update Fines information</h1>\n"); out.write(" <form name=\"Update\" action=\"Fines_upd.jsp\">\n"); out.write(" <table border=\"0\" width=\"3\" cellspacing=\"2\">\n"); out.write(" <thead>\n"); out.write(" <tr>\n"); out.write(" <th>Update Fines</th>\n"); out.write(" <th></th>\n"); out.write(" </tr>\n"); out.write(" </thead>\n"); out.write(" <tbody>\n"); out.write(" <tr>\n"); out.write(" <td>Update Fine table with todays Data</td>\n"); out.write( " <td><input type=\"submit\" value=\"Update / View Fines\" name=\"SUBMIT\"/></td>\n"); out.write(" </tr>\n"); out.write(" </tbody>\n"); out.write(" </table> \n"); out.write(" </form>\n"); out.write(" <h1>Check your Fines Here</h1>\n"); out.write(" <form name=\"Fines\" action=\"Fines.jsp\">\n"); out.write(" <table border=\"0\" width=\"3\" cellspacing=\"2\">\n"); out.write(" <thead>\n"); out.write(" <tr>\n"); out.write(" <th>Get Fine Details</th>\n"); out.write(" <th></th>\n"); out.write(" </tr>\n"); out.write(" </thead>\n"); out.write(" <tbody>\n"); out.write(" <tr>\n"); out.write(" <td>Card No</td>\n"); out.write( " <td><input type=\"text\" name=\"Card_no\" value=\"\"/></td>\n"); out.write(" </tr>\n"); out.write(" <tr>\n"); out.write(" <td></td>\n"); out.write( " <td><input type=\"submit\" value=\"Get Fines\" name=\"SUBMIT\" /></td>\n"); out.write(" </tr>\n"); out.write(" </tbody>\n"); out.write(" </table> \n"); out.write(" "); Connection con = null; String[] selected_Checkboxes = request.getParameterValues("chk"); PreparedStatement pst = null; ResultSet result = null; ResultSet resUpd = null; con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/lbms_db?zeroDateTimeBehavior=convertToNull", "root", "admin12"); String Card_no = request.getParameter("Card_no"); String button = null; Date dt = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); String current_date = sdf.format(dt); if (Card_no != null && selected_Checkboxes == null) { String selSql = "SELECT l.card_no, SUM(f.fine_amt) AS total_fine, f.paid " + "FROM book_loans l, fines f " + "WHERE l.loan_id = f.loan_id AND " + "l.card_no = " + Card_no + " " + "GROUP BY l.card_no"; pst = con.prepareStatement(selSql); result = pst.executeQuery(); String box = null; String paid; String pay; Boolean chk = false; out.println("<table>"); pay = "<form action='Fines.jsp'>"; out.println(pay); out.println("<tr>"); out.println("<th>Card No</th>"); out.println("<th>Fine_Amt</th>"); out.println("<th>Paid OR Not</th>"); out.println("</tr>"); while (result.next()) { chk = true; paid = "No"; if (result.getBoolean("f.paid")) { paid = "Yes"; } out.println("<tr>"); out.println( "<td>" + result.getInt("l.card_no") + "</td><td>" + result.getString("total_fine") + "</td><td>" + paid + "</td>"); out.print("<td>"); box = "<input name='chk' value=" + result.getInt("l.card_no") + " type='checkbox'>"; out.print(box); out.print("</td>"); out.print("</tr>"); } if (chk == true) { out.println("<tr>"); out.print("<td>"); button = "<input type='submit' value='Pay Fine' name='Pay'>"; out.print(button); out.print("</td>"); out.println("</tr>"); } else { out.write( "<dialog open> <font color = 'green'>No Fine information. You owe nothing! Thank You</font> </dialog>"); } out.println("</form>"); out.println("</table>"); } else if (selected_Checkboxes != null) { String sqlLoan = null; ResultSet resultLoan = null; String sqlUpdFine = null; PreparedStatement pstUpd = null; String sqlBook = null; ResultSet rsltBook = null; char chkouts = 'N'; int length_chk = selected_Checkboxes.length; for (int i = 0; i < length_chk; i++) { // Check whether the Book is returned before paying the fine. sqlBook = "SELECT COUNT(loan_id) AS no_chkouts FROM book_loans WHERE card_no = " + selected_Checkboxes[i] + " AND date_in = '0000-00-00' AND due_date < " + current_date + ""; pst = con.prepareStatement(sqlBook); rsltBook = pst.executeQuery(); while (rsltBook.next()) { if (rsltBook.getInt("no_chkouts") > 0) { chkouts = 'Y'; } } if (chkouts == 'Y') { out.write( "<dialog open> <font color = 'red'>You have outstanding due checkouts!. Please return the books and then Pay the fine</font> </dialog>"); } // Get the corresponding loan_Ids for each customer from Fines table sqlLoan = "SELECT loan_id FROM book_loans WHERE card_no = " + selected_Checkboxes[i] + " AND date_in IS NOT NULL AND due_date < date_in"; pst = con.prepareStatement(sqlLoan); resultLoan = pst.executeQuery(); while (resultLoan.next()) { sqlUpdFine = "UPDATE fines SET paid = true WHERE loan_id = " + resultLoan.getInt("loan_id") + ""; pstUpd = con.prepareStatement(sqlUpdFine); pstUpd.executeUpdate(); out.println("Payment Updated Successfully"); } } } out.write("\n"); out.write(" </form> \n"); out.write(" </center>\n"); out.write("</body>\n"); out.write("</html>\n"); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); else throw new ServletException(t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }