Page 1 of 2 12 LastLast
Results 1 to 20 of 25
Like Tree1Likes

Thread: GUI creation to enter data in SQL table using java

  1. #1
    Parul is offline Member
    Join Date
    Jan 2016
    Posts
    13
    Rep Power
    0

    Default GUI creation to enter data in SQL table using java

    Please help me solve 6th and 7th point in the given attachment.
    Attached Files Attached Files

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: GUI creation to enter data in SQL table using java

    Please post any specific java programming questions you have here on the forum.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    878
    Rep Power
    11

    Default Re: GUI creation to enter data in SQL table using java

    6th one is purely SQL based selection query.
    7th one is based on what kind of application you are planning to make out.
    Ramya:cool:

  4. #4
    Parul is offline Member
    Join Date
    Jan 2016
    Posts
    13
    Rep Power
    0

    Default Re: GUI creation to enter data in SQL table using java

    Sir, I don't have any specific query. I am not able to solve the above mentioned two points.

  5. #5
    Parul is offline Member
    Join Date
    Jan 2016
    Posts
    13
    Rep Power
    0

    Default Re: GUI creation to enter data in SQL table using java

    Sir, we do not have solve 6th using SQL. Data is to be entered in table with java. Also, the 7th one is report making using Jasper Reports. Kindly help!

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: GUI creation to enter data in SQL table using java

    Can't you post the problems here as part of your post rather than a PDF?

    Also, you should be able to show us what you've tried so far.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    Parul is offline Member
    Join Date
    Jan 2016
    Posts
    13
    Rep Power
    0

    Default Re: GUI creation to enter data in SQL table using java

    Ok sir.

  8. #8
    Parul is offline Member
    Join Date
    Jan 2016
    Posts
    13
    Rep Power
    0

    Default Re: GUI creation to enter data in SQL table using java

    Sir, please check my code below. The insertion is not taking place in database. Kindly help!

    package javaapp;
    import java.awt.event.*;
    import java.sql.*;
    import javax.swing.*;
    public class TableDemo extends JFrame
    {
    JLabel JL_polno,JL_agentno,JL_poldate,JL_custname,JL_pola mnt,JL_comm;
    JTextField JT_polno,JT_agentno,JT_poldate,JT_custname,JT_pola mnt,JT_comm;
    JButton btn_insert,btn_update,btn_delete;


    public void theQuery(String query)
    {
    Connection conn=null;
    PreparedStatement pstmt=null;
    try{
    Class.forName("com.mysql.jdbc.Driver");
    String url="jdbc:mysql:///insurance";
    conn=DriverManager.getConnection(url,"root","");
    System.out.println(conn);
    pstmt=conn.prepareStatement(query);

    //JOptionPane.showMessageDialog(null,"Connected to database");
    // stmt.executeUpdate(query);
    JOptionPane.showMessageDialog(null,"Query Executed");
    conn.close();
    }
    catch(Exception e)
    {
    System.out.println(e);
    }
    }

    public TableDemo()
    {
    //setTitle("Table Entries");
    super("Insert Update Delete");
    JL_polno=new JLabel("Policy no.:");
    JL_agentno=new JLabel("Agent no.:");
    JL_poldate=new JLabel("Policy date:");
    JL_custname=new JLabel("Customer name:");
    JL_polamnt=new JLabel("Policy amount:");
    JL_comm=new JLabel("Commission:");
    JL_polno.setBounds(20,20,100,20);
    JL_agentno.setBounds(20,50,100,20);
    JL_poldate.setBounds(20,80,100,20);
    JL_custname.setBounds(20,110,100,20);
    JL_polamnt.setBounds(20,140,100,20);
    JL_comm.setBounds(20,170,100,20);

    JT_polno=new JTextField(20);
    JT_agentno=new JTextField(20);
    JT_poldate=new JTextField(20);
    JT_custname=new JTextField(20);
    JT_polamnt=new JTextField(20);
    JT_comm=new JTextField(20);
    JT_polno.setBounds(130,20,150,20);
    JT_agentno.setBounds(130,50,150,20);
    JT_poldate.setBounds(130,80,150,20);
    JT_custname.setBounds(130,110,150,20);
    JT_polamnt.setBounds(130,140,150,20);
    JT_comm.setBounds(130,170,150,20);

    btn_insert=new JButton("Insert");
    btn_update=new JButton("Update");
    btn_delete=new JButton("Delete");
    btn_insert.setBounds(300,50,80,20);
    btn_update.setBounds(300,80,80,20);
    btn_delete.setBounds(300,110,80,20);

    setLayout(null);
    add(JL_polno);
    add(JL_agentno);
    add(JL_poldate);
    add(JL_custname);
    add(JL_polamnt);
    add(JL_comm);
    add(JT_polno);
    add(JT_agentno);
    add(JT_poldate);
    add(JT_custname);
    add(JT_polamnt);
    add(JT_comm);
    add(btn_insert);
    add(btn_update);
    add(btn_delete);

    btn_insert.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    try
    {
    theQuery("insert into policy_details(polno,agentno,poldate,custname,pola mnt)values('"+JT_polno.getText()+"','"+JT_agentno. getText()+"','"+JT_poldate.getText()+"','"+JT_cust name.getText()+"','"+JT_polamnt.getText()+")");
    System.out.println(JT_polno.getText());
    }
    catch(Exception ex)
    {
    System.out.println(ex);
    }
    }
    });


    btn_update.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    try
    {
    theQuery("update policy_details set agentno='"+JT_agentno.getText()+"',poldate='"+JT_p oldate.getText()+"',custname='"+JT_custname.getTex t()+"',polamnt='"+JT_polamnt.getText()+"where polno="+JT_polno.getText());
    }
    catch(Exception exp)
    {
    System.out.println(exp);
    }
    }
    });



    btn_delete.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    try
    {
    theQuery("delete from policy_details where polno="+JT_polno.getText());
    }
    catch(Exception excp)
    {
    System.out.println(excp);
    }
    }
    });

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setVisible(true);

    setLocationRelativeTo(null);

    setSize(500,300);
    // show();

    }

    public static void main(String args[ ])
    {
    new TableDemo( );
    }
    }

  9. #9
    Parul is offline Member
    Join Date
    Jan 2016
    Posts
    13
    Rep Power
    0

    Default Re: GUI creation to enter data in SQL table using java

    Sir, please check my code below. The insertion is not taking place in database. Kindly help!

    package javaapp;
    import java.awt.event.*;
    import java.sql.*;
    import javax.swing.*;
    public class TableDemo extends JFrame
    {
    JLabel JL_polno,JL_agentno,JL_poldate,JL_custname,JL_pola mnt,JL_comm;
    JTextField JT_polno,JT_agentno,JT_poldate,JT_custname,JT_pola mnt,JT_comm;
    JButton btn_insert,btn_update,btn_delete;


    public void theQuery(String query)
    {
    Connection conn=null;
    PreparedStatement pstmt=null;
    try{
    Class.forName("com.mysql.jdbc.Driver");
    String url="jdbc:mysql:///insurance";
    conn=DriverManager.getConnection(url,"root","");
    System.out.println(conn);
    pstmt=conn.prepareStatement(query);

    //JOptionPane.showMessageDialog(null,"Connected to database");
    // stmt.executeUpdate(query);
    JOptionPane.showMessageDialog(null,"Query Executed");
    conn.close();
    }
    catch(Exception e)
    {
    System.out.println(e);
    }
    }

    public TableDemo()
    {
    //setTitle("Table Entries");
    super("Insert Update Delete");
    JL_polno=new JLabel("Policy no.:");
    JL_agentno=new JLabel("Agent no.:");
    JL_poldate=new JLabel("Policy date:");
    JL_custname=new JLabel("Customer name:");
    JL_polamnt=new JLabel("Policy amount:");
    JL_comm=new JLabel("Commission:");
    JL_polno.setBounds(20,20,100,20);
    JL_agentno.setBounds(20,50,100,20);
    JL_poldate.setBounds(20,80,100,20);
    JL_custname.setBounds(20,110,100,20);
    JL_polamnt.setBounds(20,140,100,20);
    JL_comm.setBounds(20,170,100,20);

    JT_polno=new JTextField(20);
    JT_agentno=new JTextField(20);
    JT_poldate=new JTextField(20);
    JT_custname=new JTextField(20);
    JT_polamnt=new JTextField(20);
    JT_comm=new JTextField(20);
    JT_polno.setBounds(130,20,150,20);
    JT_agentno.setBounds(130,50,150,20);
    JT_poldate.setBounds(130,80,150,20);
    JT_custname.setBounds(130,110,150,20);
    JT_polamnt.setBounds(130,140,150,20);
    JT_comm.setBounds(130,170,150,20);

    btn_insert=new JButton("Insert");
    btn_update=new JButton("Update");
    btn_delete=new JButton("Delete");
    btn_insert.setBounds(300,50,80,20);
    btn_update.setBounds(300,80,80,20);
    btn_delete.setBounds(300,110,80,20);

    setLayout(null);
    add(JL_polno);
    add(JL_agentno);
    add(JL_poldate);
    add(JL_custname);
    add(JL_polamnt);
    add(JL_comm);
    add(JT_polno);
    add(JT_agentno);
    add(JT_poldate);
    add(JT_custname);
    add(JT_polamnt);
    add(JT_comm);
    add(btn_insert);
    add(btn_update);
    add(btn_delete);

    btn_insert.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    try
    {
    theQuery("insert into policy_details(polno,agentno,poldate,custname,pola mnt)values('"+JT_polno.getText()+"','"+JT_agentno. getText()+"','"+JT_poldate.getText()+"','"+JT_cust name.getText()+"','"+JT_polamnt.getText()+")");
    System.out.println(JT_polno.getText());
    }
    catch(Exception ex)
    {
    System.out.println(ex);
    }
    }
    });


    btn_update.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    try
    {
    theQuery("update policy_details set agentno='"+JT_agentno.getText()+"',poldate='"+JT_p oldate.getText()+"',custname='"+JT_custname.getTex t()+"',polamnt='"+JT_polamnt.getText()+"where polno="+JT_polno.getText());
    }
    catch(Exception exp)
    {
    System.out.println(exp);
    }
    }
    });



    btn_delete.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    try
    {
    theQuery("delete from policy_details where polno="+JT_polno.getText());
    }
    catch(Exception excp)
    {
    System.out.println(excp);
    }
    }
    });

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setVisible(true);

    setLocationRelativeTo(null);

    setSize(500,300);
    // show();

    }

    public static void main(String args[ ])
    {
    new TableDemo( );
    }
    }

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: GUI creation to enter data in SQL table using java

    Please edit your post and wrap your code with code tags:
    [code]
    **YOUR CODE GOES HERE**
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    Parul is offline Member
    Join Date
    Jan 2016
    Posts
    13
    Rep Power
    0

    Default Re: GUI creation to enter data in SQL table using java

    Java Code:
    package javaapp;
    import java.awt.event.*;
    import java.sql.*;
    import javax.swing.*;
    public class TableDemo extends JFrame
    {
    JLabel JL_polno,JL_agentno,JL_poldate,JL_custname,JL_pola mnt,JL_comm;
    JTextField JT_polno,JT_agentno,JT_poldate,JT_custname,JT_pola mnt,JT_comm;
    JButton btn_insert,btn_update,btn_delete;
    
    
    public void theQuery(String query)
    {
    Connection conn=null;
    PreparedStatement pstmt=null;
    try{
    Class.forName("com.mysql.jdbc.Driver");
    String url="jdbc:mysql:///insurance";
    conn=DriverManager.getConnection(url,"root","");
    System.out.println(conn);
    pstmt=conn.prepareStatement(query);
    
    //JOptionPane.showMessageDialog(null,"Connected to database");
    // stmt.executeUpdate(query);
    JOptionPane.showMessageDialog(null,"Query Executed");
    conn.close();
    }
    catch(Exception e)
    {
    System.out.println(e);
    }
    }
    
    public TableDemo()
    {
    //setTitle("Table Entries");
    super("Insert Update Delete");
    JL_polno=new JLabel("Policy no.:");
    JL_agentno=new JLabel("Agent no.:");
    JL_poldate=new JLabel("Policy date:");
    JL_custname=new JLabel("Customer name:");
    JL_polamnt=new JLabel("Policy amount:");
    JL_comm=new JLabel("Commission:");
    JL_polno.setBounds(20,20,100,20);
    JL_agentno.setBounds(20,50,100,20);
    JL_poldate.setBounds(20,80,100,20);
    JL_custname.setBounds(20,110,100,20);
    JL_polamnt.setBounds(20,140,100,20);
    JL_comm.setBounds(20,170,100,20);
    
    JT_polno=new JTextField(20);
    JT_agentno=new JTextField(20);
    JT_poldate=new JTextField(20);
    JT_custname=new JTextField(20);
    JT_polamnt=new JTextField(20);
    JT_comm=new JTextField(20);
    JT_polno.setBounds(130,20,150,20);
    JT_agentno.setBounds(130,50,150,20);
    JT_poldate.setBounds(130,80,150,20);
    JT_custname.setBounds(130,110,150,20);
    JT_polamnt.setBounds(130,140,150,20);
    JT_comm.setBounds(130,170,150,20);
    
    btn_insert=new JButton("Insert");
    btn_update=new JButton("Update");
    btn_delete=new JButton("Delete");
    btn_insert.setBounds(300,50,80,20);
    btn_update.setBounds(300,80,80,20);
    btn_delete.setBounds(300,110,80,20);
    
    setLayout(null);
    add(JL_polno);
    add(JL_agentno);
    add(JL_poldate);
    add(JL_custname);
    add(JL_polamnt);
    add(JL_comm);
    add(JT_polno);
    add(JT_agentno);
    add(JT_poldate);
    add(JT_custname);
    add(JT_polamnt);
    add(JT_comm);
    add(btn_insert);
    add(btn_update);
    add(btn_delete);
    
    btn_insert.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    try
    {
    theQuery("insert into policy_details(polno,agentno,poldate,custname,pola mnt)values('"+JT_polno.getText()+"','"+JT_agentno. getText()+"','"+JT_poldate.getText()+"','"+JT_cust name.getText()+"','"+JT_polamnt.getText()+")");
    System.out.println(JT_polno.getText());
    }
    catch(Exception ex)
    {
    System.out.println(ex);
    }
    }
    });
    
    
    btn_update.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    try
    {
    theQuery("update policy_details set agentno='"+JT_agentno.getText()+"',poldate='"+JT_p oldate.getText()+"',custname='"+JT_custname.getTex t()+"',polamnt='"+JT_polamnt.getText()+"where polno="+JT_polno.getText());
    }
    catch(Exception exp)
    {
    System.out.println(exp);
    }
    }
    });
    
    
    
    btn_delete.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    try
    {
    theQuery("delete from policy_details where polno="+JT_polno.getText());
    }
    catch(Exception excp)
    {
    System.out.println(excp);
    }
    }
    });
    
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    setVisible(true);
    
    setLocationRelativeTo(null);
    
    setSize(500,300);
    // show();
    
    }
    
    public static void main(String args[ ])
    {
    new TableDemo( );
    }
    }

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: GUI creation to enter data in SQL table using java

    The code has lost all its indentations making it harder to read.

    How can the code be tested? Does it require a DB file on the user's PC? Do you have code to build a testing DB?
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    Parul is offline Member
    Join Date
    Jan 2016
    Posts
    13
    Rep Power
    0

    Default Re: GUI creation to enter data in SQL table using java

    Yes sir, it requires a DB file. Please tell me how can I provide DB to you?
    Also please suggest how can the indentations be intact so that it is readable?
    Last edited by Parul; 01-31-2016 at 02:04 PM.

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: GUI creation to enter data in SQL table using java

    how can the indentations be intact
    When you paste code with indentations between code tags, the indentations shouldn't be lost.
    An example:
    Java Code:
          int idx = 0;
          for(int row=0; row < board.length; row++) {
             for (int col=0; col < board.length; col++) {
                board[row][col] = new Pixel(row, col);
             }
          }
    how can I provide DB
    Provide a small simple text file and a program to read that file, create and build the DB.

    The insertion is not taking place in database.
    Do you get any error messages when the insert statement is executed?
    Last edited by Norm; 01-31-2016 at 04:18 PM.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: GUI creation to enter data in SQL table using java

    I'm going to guess you;re getting an error:
    Java Code:
    // line 94
    insert into policy_details(polno,agentno,poldate,custname,pola mnt)
    compared with:
    Java Code:
    // line 111
    update policy_details set ... polamnt=
    So, is that column named "pola mnt" (with a space) or "polamnt" (without a space)?

    And if you do get an exception you should remember to post it as part of your question as it contains important information to help solve any issues.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #16
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    878
    Rep Power
    11

    Default Re: GUI creation to enter data in SQL table using java

    better use PreparedStatement...these type of query will create lot of errors..print the query formation and try to run in DB editor directly.
    Ramya:cool:

  17. #17
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: GUI creation to enter data in SQL table using java

    And I believe it can be a major security risk.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: GUI creation to enter data in SQL table using java

    Ah, but they are using a PreparedStatement...it's just not actually being used as a PreparedStatement.

    The code should be changed to use it properly, though, but I would say that's secondary to the current issues.
    It's a desktop app, so unless it's sharing a DB across the internet the security is less of a problem. And if it is shared across the internet then that in itself is a bigger issue.
    RamyaSivakanth likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  19. #19
    Parul is offline Member
    Join Date
    Jan 2016
    Posts
    13
    Rep Power
    0

    Default Re: GUI creation to enter data in SQL table using java

    Sir, in my code in netbeans there is no such space in polamnt. I don't know how space came !!

  20. #20
    Parul is offline Member
    Join Date
    Jan 2016
    Posts
    13
    Rep Power
    0

    Default Re: GUI creation to enter data in SQL table using java

    Sir, I am not able to take dump of my mysql db. It is showing some localhost error.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 05-18-2012, 01:29 PM
  2. Replies: 1
    Last Post: 05-15-2012, 05:25 AM
  3. Error in table creation
    By asifzbaig in forum JDBC
    Replies: 2
    Last Post: 06-11-2011, 11:25 PM
  4. Replies: 11
    Last Post: 01-18-2011, 03:57 AM
  5. enter data from an optic device
    By bbq in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 08:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •