Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ankur Pachegaokar
This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible
0 Answer(s)      a year and 2 months ago
Posted in : JDBC


import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField;

/** * * @author Ankur Pachegaokar */ public class InsertData extends JFrame implements ActionListener { JLabel l1,l2,l3,l4; JTextField tf1,tf2,tf3,tf4; JButton b;

InsertData() 
{
    Container c=getContentPane();
    c.setLayout(new FlowLayout());

    l1=new JLabel("Emp_Id");
    tf1=new JTextField(20);

    l2=new JLabel("F_Name");
    tf2=new JTextField(20);

    l3=new JLabel("M_Name");
    tf3=new JTextField(20);

    l4=new JLabel("L_Name");
    tf4=new JTextField(20);

    b=new JButton("Insert");

    c.add(l1);
    c.add(tf1);
    c.add(l2);
    c.add(tf2);
    c.add(l3);
    c.add(tf3);
    c.add(l4);
    c.add(tf4);

    c.add(b);

    b.addActionListener(this);



    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

@Override
public void actionPerformed(ActionEvent ae)
{
    if("Insert".equals(ae.getActionCommand()))
    {
        int Emp_id=Integer.parseInt(tf1.getText());
        String F_name=tf2.getText();
        String M_name=tf3.getText();
        String L_name=tf4.getText();

        try
        {
          Class.forName(com.mysql.jdbc.Driver).newInstance();
          Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/employee_database","root","root");
          Statement st=con.createStatement();
          System.out.println("query======for insert >>");
          st.executeUpdate("INSERT INTO emp_data (Emp_id,F_name,M_name,L_name) VALUES ("+Emp_id+",'"+F_name+"','"+M_name+"','"+L_name+"')");
          System.out.println("Data Sucessfully inserted.......");

           //con.close();


        }
        catch(Exception e)
        {
            System.out.println(e);
        }
       /* System.out.println(Emp_id);
        System.out.println(F_name);
        System.out.println(M_name);
        System.out.println(L_name);*/


    }
}
public static void main(String args[]) throws Exception
{
    InsertData id=new InsertData();
    id.setTitle("Employee Info");
    id.setSize(400, 500);
    id.setVisible(true);




print("code sample");

}print("code sample");

Advertisement
View Answers

Related Tutorials/Questions & Answers:
hi see and give me reply as soon as possible
hi see and give me reply as soon as possible  Hi Friend, I got path,but it will again ask path error first i was gave index.jsp.It.../hello) is not available. JBoss Web/2.1.2.GA above error will displayed pls
pls give me answer ae soon as possible - Ajax
pls give me answer ae soon as possible  i m writing code of ajax technology ...but it is not working pls check it n give me response quickly... give me quick response!!! thanks & regards shashank gupta
Advertisements
Please help me to write a code for add contacts to groups in a website?
Please help me to write a code for add contacts to groups in a website?   Iam developing a site. In that site I need to write code for Groups... send a code for this? Please make it fast
please help me to give code - Java Beginners
please help me to give code  Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot: Gimme an R Gimme an O Gimme a B Gimme an O Gimme a T What did you give me? ROBOT
please help me to give code - Java Beginners
please help me to give code  Write a program that prints an n-level...!"); String str = buff.readLine(); int i=1; int j; while(i<=4){ for(j=1;j<=i;j++) System.out.print(str); i=i+1; System.out.println
please help me to give code - Java Beginners
please help me to give code  Write a program that uses loops...; k<=4; k++){ System.out.print(k+"|"); for (int i=1; i<=4; i++){ System.out.print(i); } System.out.println
please help me to give code - Java Beginners
please help me to give code  Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4
please help me to give code - Java Beginners
please help me to give code  Write a program that reads a file named famous.txt and prints out the line with the longest length. In the case of a tie, you may print out only one of them. For example in the file: Alan Turing
plz plz plz inform me as soon as possible
plz plz plz inform me as soon as possible  ``by using c programs how to type
I GOT ERROR FOR MY PROJECT
I GOT ERROR FOR MY PROJECT  Dear Friend/ RoseIndia Team, Firstly I would to thank u Guys help me so many time.. I got error on my little project when running at server. please correctly my error Guys... ERROR CODE: "LOGIN
Please give me the answer.
"int a=08 or 09" its giving compile time error why   "int a=08 or 09" its giving compile time error why ? can any one give me the answer of this please
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1
please help me to write a code for this program
please help me to write a code for this program   1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
how to send email please give me details with code in jsp,servlet
how to send email please give me details with code in jsp,servlet  how to send email please give me details with code in jsp,servlet
Please give me coding for this..
Please give me coding for this..  Write an application that inputs one number consisting of five digits from the user.separates the number ibto its individual digits and prints the digits separated from one another by three
i got illegal start of expression error , plese tell me the mistake where i did...
i got illegal start of expression error , plese tell me the mistake where i did...   import org.springframework.context.*; import java.util.*; public class MyListener implements ApplicationListener { public static void main
Please give me the code for the below problem - Java Interview Questions
Please give me the code for the below problem  PROBLEM : SALES TAXES... applicable on all imported goods at a rate of 5%, with no exemptions. When I purchase items I receive a receipt which lists the name of all the items
creating a feedback form - JSP-Servlet
for providing me the solution for the problem entitled "inserting the data from radio button into database". the code you gave is working absolutely fine. but now i am refining this problem as follows: i am creating a feedback form
how can i write this program ?please suggest me
how can i write this program ?please suggest me  Program to calculate the sum of two big numbers (the numbers can contain more than 1000 digits). Don't use any library classes or methods (BigInteger etc
i got an error while compile this program manually.
i got an error while compile this program manually.  import...,struts jar files and i got an error in saveErrors() error Heading cannot find..., ActionForm form, HttpServletRequest request
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  1) Copy one file content to other? 2) Count the number of words in a file
please any one can help me to write a code for this question?
please any one can help me to write a code for this question?  Q 1) In a class first day 25 students are joined. After two days that total students will increased to 60. We can develop a program by using ArrayList concept
hi, Everyone ,i'm learning jdbc, i got an nullpointerexception when execute this program.
hi, Everyone ,i'm learning jdbc, i got an nullpointerexception when execute this program.   ConnectionProvider.java import java.util.*; import java.io.*; import java.sql.*; class ConnectionProvider { static Properties prop
I want to update the multiple values of database depending on checkbox..? Please help me out..
I want to update the multiple values of database depending on checkbox..? Please help me out..   Hi .. I want to Update the multiple values.....? please answer if any one knows as soon as possible..? Thanks in Advance
i want java code for this xml file...please show me..
i want java code for this xml file...please show me..   xbrli:shares xbrli:pure iso4217:INR
this is my javascript code and i am not understanding the mistake in this,please help me?
this is my javascript code and i am not understanding the mistake in this,please help me?  <html> <h2>Form Validation</h2>...; if((nn1.value==null)||(nn1.value=="")){ alert("Please Enter
please give me an idea to develop a program for this question?
please give me an idea to develop a program for this question?  How to enter a text or number from keyboard without using InputStreamReader method in java
please give me a java program for the following question
please give me a java program for the following question  Write...; In the previous code, we forget to add an icon to button. So we are sending the updated code. import java.awt.*; import javax.swing.*; import
to write a program to display the employee details..
the employee details.please send me the code .it's urgent.send me as soon as possible... the details in a new windowusing java swings...please help me as soon... me the code soon.....it is some what urgent for me......thank u.... madhuri
Plz give me code for this question
Plz give me code for this question  Program to find depth of the file in a directory and list all files those are having more number of parent directories
Give me the source code for this problem
Give me the source code for this problem  Ram likes skiing a lot... help to know the longest run possible with the given peaks. That altitude... map, a possible ski path would be 36-33-24(start at 36, end at 24). Of course
Advertisements
 

 

 

DMCA.com