Hi,
In my last reply to this thread my suggesstion got mixed up with the code and so i
am resending it to the posting, please bear.
Hi everyone,Thanks to Yogesh and Stephen Raj Arokiasamy for the
quick
> response but the problem still persists.I am using a system dsn
called
> mjs.At compile time there r no errors only 1 warning but as soon
as I
> run this code it hangs.I agree that I have not added a window
listener
> nut the system.exit(1) sould at least allow me to exit.Please do
> help,Thanks in advance,MJSimport java.sql.*;
> import java.awt.*;
> import java.awt.event.*;
> import java.util.*;
> import sun.jdbc.odbc.JdbcOdbcDriver; public class nayausr extends
> Frame implements ActionListener
> {
> String temp,temp1,temp2;
> static Connection con;
> public static void main(String s[])
> {
> nayausr t=new nayausr();
> t.setLayout(new FlowLayout());
> t.setSize(500,500);
> t.create(t);
> } public void create(nayausr f)
> {
> Label lbel=new Label("Please enter new user details");
> Label lb=new Label("
> ");
> Label l1=new Label("Username : ");
> TextField t1=new TextField(20);
> Label l2=new Label(" Password : ");
> TextField t2=new TextField(20);
> Label l3=new Label(" Employee number : ");
> TextField t3=new TextField(20);
> t2.setEchoCharacter('*');
> Label lb1=new Label(" ");
Button
> b=new Button();
> b.setLabel("SUBMIT");
> b.addActionListener(f);
> f.add(lbel);
> f.add(l1);
> f.add(t1);
> f.add(lb);
> f.add(l2);
> f.add(t2);
> f.add(lb1);
> f.add(l3);
> f.add(t3); f.add(b);
> temp =t1.getText();
> temp1 =t3.getText();
>
Do not assign the values to temp, temp1 here. The textfields don't
contain data as yet. Do it in the actionPerformed method just
before
calling the Db function. Also declare all the GUI components as
member
variables and instantiate them in the create method, otherwise you
won't be able to access them in the actionPerformed method. And as
others have mentioned get rid of the exit call.
Try to use an IDE (JBuilder), see the code generated and follow its coding style.
Hope this helps.
Bye.
-Kiran.
>
>
>
> f.setVisible(true);
> } public void actionPerformed(ActionEvent e)
> {
> String s=e.getActionCommand();
> if (s.equals("SUBMIT"))
> {
> Db(temp,temp1);
> }
> } public void Db(String te1,String te2)
> {
> String url="jdbc:odbc:mjs";
> try
> {
> try
> {Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
> catch (Exception e){}
> con=DriverManager.getConnection(url,"",""); Statement
> s1=con.createStatement(); String qq="INSERT INTO abc
> VALUES('"+"'"+te1+"','" +te2+"' )";
> s1.executeUpdate(qq);
> System.exit(1);
> System.out.println("INSERTED SUCCESSFULLY " ); s1.close();
> con.close();
> } catch(SQLException e)
> { }
> finally
> {
> try {con.close();
> }
> catch (Exception w){}
> } } }
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html