validating string between jdbc and textfield
Hi guys,
I am having a problem with JDBC. I am posting the app here. The problem is, I couldnt compare the testfield text and the database string. Am i doing something wrong or is there any other way?
******************************************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class test extends JFrame implements ActionListener{
JTextField tid;
JTextField tpass;
public test(){
JLabel id=new JLabel("ID");
JLabel pass=new JLabel("Password");
tid=new JTextField(10);
tpass=new JTextField(10);
JButton validate=new JButton("VALIDATE");
GridBagLayout g1=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
Container content=getContentPane();
content.setLayout(g1);
gbc.anchor=GridBagConstraints.CENTER;
gbc.gridx=0;
gbc.gridy=0;
g1.setConstraints(id,gbc);
content.add(id);
gbc.anchor=GridBagConstraints.CENTER;
gbc.gridx=2;
gbc.gridy=0;
g1.setConstraints(tid,gbc);
content.add(tid);
gbc.anchor=GridBagConstraints.CENTER;
gbc.gridx=0;
gbc.gridy=1;
g1.setConstraints(pass,gbc);
content.add(pass);
gbc.anchor=GridBagConstraints.CENTER;
gbc.gridx=2;
gbc.gridy=1;
g1.setConstraints(tpass,gbc);
content.add(tpass);
gbc.anchor=GridBagConstraints.CENTER;
gbc.gridx=1;
gbc.gridy=2;
g1.setConstraints(validate,gbc);
content.add(validate);
validate.addActionListener(this);
}
public void actionPerformed(ActionEvent evt){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con;
con=DriverManager.getConnection("jdbc:odbc:javatest","sa",null);
PreparedStatement stat=con.prepareStatement("select * from javatest where cid=?");
stat.setString(1,tid.getText());
ResultSet result=stat.executeQuery();
while(result.next())
{
System.out.println("REached");
if(result.getString(2)==tpass.getText())
System.out.println("Successfulll");
else
System.out.println("Failure");
}
}catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String args[]){
test t1=new test();
t1.setSize(300,300);
t1.setVisible(true);
}
}
******************************************
here is the sql code:
create table javatest
(
cid varchar(10),
pass varchar(10
)
reply please, thanks.

