private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
DefaultListModel list = (DefaultListModel) jList1.getModel();
String sql = "Select * from salesorder";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/userauthentication", "root", "");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
Integer id = rs.getInt("id");
list.addElement(id);
}
jList1.setModel(list);
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
}

private void jList1MouseClicked(java.awt.event.MouseEvent evt) {                                    
    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/userauthentication", "root", "");
        Statement stmt = con.createStatement();
        Integer no = (Integer) jList1.getSelectedValue();
        String sql1 = "Select * from salesorder where id= '" + (no) + "'";
        ResultSet rs = stmt.executeQuery(sql1);
        while (rs.next()) {
            Integer id = rs.getInt("id");
            String Brand = rs.getString("Brand");
            String Product = rs.getString("Product");
            String Model = rs.getString("Model");
            Integer Quantity = rs.getInt("Quantity");
            Double Price = rs.getDouble("Price");
            String Customer = rs.getString("Customer");
            Date date = rs.getDate("Date");
            jTextField8.setText("" + id);
            jTextField1.setText("" + Brand);
            jTextField2.setText("" + Product);
             jTextField3.setText("" yyyy-mm-dd);




            jTextField4.setText("" + Model);
            jTextField5.setText("" + Quantity);
            jTextField6.setText("" + Price);
            jTextField7.setText("" + Customer);



        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, e.getMessage());
    }// TODO add your handling code here:
}         

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/userauthentication", "root", "");
        Statement stmt = con.createStatement();
        Integer no = (Integer) jList1.getSelectedValue();
        Integer id = Integer.parseInt(jTextField8.getText());
        String Brand = jTextField1.getText();
        String Model = jTextField4.getText();
        String Customer = jTextField7.getText();
        String Product = jTextField2.getText();
        Integer Quantity = Integer.parseInt(jTextField5.getText());



        String Date = jTextField3.getText();
        Double Price = Double.parseDouble(jTextField6.getText());
        String sql1 = "Update salesorder set id='" + (id) + "', Brand='" + (Brand) + "', Model='" + (Model) + "', Customer='" + (Customer) + "', Product='" + (Product) + "', Quantity='" + (Quantity) + "',Price='" + (Price) + "', Date='" + (Date) + "' where id = '" + (no) + "'";

        stmt.executeUpdate(sql1);

    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, e.getMessage());
    }

Recommended Answers

All 8 Replies

What exactly is you problem/question?

i am not able to retrieve the stored date in textfield. i have problem in its code. i am writing jTextField3.setText(""+Date); but its showing error

and what exactly is the error that it is showing?

operator + cannot be applied to java.lang.String,Date

actually i want to display the date(yyyy-mm--dd) in textfield .database is in mysql

What date do you want to display?

ps: Date (capital D) is the name of a class. date (small d) is a variable. Check your capitalisation.

thanks a lot for helping me out Sir..

how can i convert a java application form to a printable format or to a text document.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.