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
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");
View Answers
Related Tutorials/Questions & Answers:
hi see and give me reply as soon as possiblehi 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 - Ajaxpls
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 give code - Java Beginnersplease 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 Beginnersplease 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 Beginnersplease 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 Beginnersplease 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
I GOT ERROR FOR MY PROJECTI 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 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
how can i write this program ?please suggest mehow 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
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 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 questionPlz
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 problemGive 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
programming error for the respective name"
error i got is:SQL exception
please give me the solution by providing the exact coding,as
soon as
possible...programming error
I got an
error when
i did the following program
error please send me the solutionerror please send
me the solution HTTP Status 500 -
type Exception report
message
description The server encountered an internal
error...
java.sql.SQLException: No suitable driver found for jdbc:
mysql//localhost:3306/mysql
error please send me the solutionerror please send
me the solution HTTP Status 500 -
type Exception report
message
description The server encountered an internal
error...
java.sql.SQLException: No suitable driver found for jdbc:
mysql//localhost:3306/mysql
retrieve data from mysql databaseretrieve
data from
mysql database hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant
data from
mysql database using php.... below my
code is that..
<html>
<head>