I want to enter a data from the text field to my database named project marking. When I compile the java program seems there's no errors but when I click on the Calculate Button the data won't enter into the database. This is the partial code I didn't finished it yet.

import java.awt.event.*;//Package Event Handling
import javax.swing.*;   //Package Swing
import java.awt.*;  //Package AWT
import java.sql.*;  //Package SQL
//Packages imported

public class PBT extends JFrame 
//implements ItemListener
{
    //Declaration for each components 
    //Label
    JLabel regnum= new JLabel("Registration Number: ");
    JLabel name= new JLabel("Name: ");
    JLabel peer1= new JLabel("Peer Assessment 1: ");
    JLabel peer2= new JLabel("Peer Assessment 2: ");
    JLabel peer3= new JLabel("Peer Assessment 3: ");
    JLabel totalpeer= new JLabel("Total Peer Assessment: ");
    JLabel presentation1= new JLabel("Presentation 1: ");
    JLabel presentation2= new JLabel("Presentation 2: ");
    JLabel presentation3= new JLabel("Presentation 3: ");
    JLabel total25= new JLabel("Total Presentation(25%): ");
    JLabel presentation4= new JLabel("Presentation(15%): ");
    JLabel capstone= new JLabel("Total Capstone(50%): ");
    JLabel totalscore= new JLabel("Total Score: ");
    JLabel disptotalscore= new JLabel("Remove this text after testing");

    //Button
    JButton calculateBtn= new JButton("Calculate");
    JButton resetBtn= new JButton("Reset");

    //TextField
    JTextField regnumTf= new JTextField(15);
    JTextField nameTf= new JTextField(30);
    JTextField peer1Tf= new JTextField(15);
    JTextField peer2Tf= new JTextField(15);
    JTextField peer3Tf= new JTextField(15);
    JTextField totalpeerTf= new JTextField(15);
    JTextField presentation1Tf= new JTextField(15);
    JTextField presentation2Tf=new JTextField(15);
    JTextField presentation3Tf=new JTextField(15);
    JTextField total25Tf=new JTextField(15);
    JTextField presentation4Tf=new JTextField(15);
    JTextField capstoneTf=new JTextField(15);

    //Declaring Border Layout
    BorderLayout border=new BorderLayout();
    //Declaring Grid Layout
    GridLayout gridlayout=new GridLayout(0,1);

    //Creating 4 Panels

    JPanel pnl2=new JPanel();
    JPanel pnl3=new JPanel();
    JPanel pnl4=new JPanel();

    public PBT()
    {
        pnl3.add(regnum);
        pnl4.add(regnumTf);
        pnl3.add(name);
        pnl4.add(nameTf);
        pnl2.add(calculateBtn);
        pnl2.add(resetBtn);
        pnl3.add(peer1);
        pnl3.add(peer2);
        pnl3.add(peer3);
        pnl3.add(totalpeer);
        pnl3.add(presentation1);
        pnl3.add(presentation2);
        pnl3.add(presentation3);
        pnl3.add(total25);
        pnl3.add(presentation4);
        pnl3.add(capstone);
        //pnl3.add(totalscore);
        pnl4.add(peer1Tf);
        pnl4.add(peer2Tf);
        pnl4.add(peer3Tf);
        pnl4.add(presentation1Tf);
        pnl4.add(presentation2Tf);
        pnl4.add(presentation3Tf);
        pnl4.add(presentation4Tf);
        pnl4.add(totalpeerTf);
        pnl4.add(total25Tf);
        pnl4.add(capstoneTf);

        //Add panel to their respective borderlayout
        add(pnl2,BorderLayout.SOUTH);
        add(pnl3,BorderLayout.WEST);
        add(pnl4,BorderLayout.CENTER);

        //Set the layout
        pnl3.setLayout(gridlayout);
        pnl4.setLayout(gridlayout);

        //Declaring Listener
        calculateBtn.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
        String regnum1=regnumTf.getText();
        String name1=nameTf.getText();
        int p1=Integer.parseInt(peer1Tf.getText());
        int p2=Integer.parseInt(peer2Tf.getText());
        int p3=Integer.parseInt(peer3Tf.getText());
        int pr1=Integer.parseInt(presentation1Tf.getText());
        int pr2=Integer.parseInt(presentation2Tf.getText());
        int pr3=Integer.parseInt(presentation3Tf.getText());
        int pr4=Integer.parseInt(presentation4Tf.getText());
        int capst=Integer.parseInt(capstoneTf.getText());



        try{
        Class.forName("com.mysql.jdbc.Driver");
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost/projectmarking","root","");
        Statement st=con.createStatement();

        int i=st.executeUpdate("insert into student(regnum,name,peer,peer2,peer3,presentation1,presentation2,presentation3,presentation,totalcapstone)values('"+regnum1+"','"+name1+"','"+p1+"','"+p2+"','"+p3+"','"+pr1+"','"+pr2+"','"+pr3+"','"+pr4+"','"+capst+"')");
        }
        catch(Exception ex){
            System.out.println(ex);
        }

        }});
    }

    public static void main(String[]args)
    {
        PBT obj=new PBT();
        obj.setTitle("PROJECT MARKING");
        obj.setVisible(true);
        obj.pack();
    }


}

I get this message when I run the program

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For inpu
t string: ""
at java.lang.NumberFormatException.forInputString(Unk nown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at PBT$1.actionPerformed(PBT.java:103)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Sour
ce)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Sour
ce)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Sour
ce)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Look through the messages until you find a reference to your code, in this case
at PBT$1.actionPerformed(PBT.java:103)
then look at that line
103 int pr1=Integer.parseInt(presentation1Tf.getText());
now you can undestand the error message
NumberFormatException: For input string: ""
presentation1Tf contained no text, and you tried to parse that as an int

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.