i want to add the new customer for that when i click on add butto the new customernumber should be display in textfield . plz ell me the suggestions & code
Java Display new value to textbox:
import java.awt.*; import java.sql.*; import javax.swing.*; import java.awt.event.*; class TextFieldExample { public static void main(String[] args){ Frame f=new Frame(); Label label1=new Label("No: "); Label label2=new Label("Name: "); Label label3=new Label("Address: "); final TextField text1=new TextField(20); final TextField text2=new TextField(20); final TextField text3=new TextField(20); text1.setText("1"); Button b=new Button("Add"); b.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ int v1=Integer.parseInt(text1.getText()); String v2=text2.getText(); String v3=text3.getText(); try{ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); Statement st=con.createStatement(); int i=st.executeUpdate("insert into user(id,name,address) values("+v1+",'"+v2+"','"+v3+"')"); JOptionPane.showMessageDialog(null,"Data is inserted successfully"); } catch(Exception ex){ System.out.println(ex); } v1=v1+1; text1.setText(Integer.toString(v1)); text2.setText(""); text3.setText(""); } }); Panel p=new Panel(new GridLayout(5,2)); p.add(label1); p.add(text1); p.add(label2); p.add(text2); p.add(label3); p.add(text3); p.add(b); f.add(p); f.setVisible(true); f.pack(); } }
Ads