Skip to main content

I Found that my code is not working on jdk1.6.0 and works on others

2 replies [Last post]
anees042
Offline
Joined: 2005-02-25

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.sql.*;

public class Login extends JFrame implements ActionListener{

JPanel upPanel,midPanel,downPanel;
SRFButton loginButton,cancelButton;
JLabel loginLabel,passLabel,bannerLabel,nickLabel;
JTextField loginField,nickTf;
JPasswordField passField;
Color backColor;
Statement st1;
ResultSet rest;
String pass,user;
String in_pass,in_user,in_nick;
ImageIcon bannerIcon;
public Login(String title){
super(title);
midPanel = new JPanel();
midPanel.setLayout(new GridLayout(3,3));
backColor = new Color(91,215,236);
midPanel.setBackground(backColor);
upPanel = new JPanel();
upPanel.setLayout(new GridLayout(1,1));
downPanel = new JPanel();
downPanel.setBackground(backColor);
loginLabel = new JLabel(" Login : ");
passLabel = new JLabel(" Password : ");
bannerIcon = new ImageIcon("banner.jpg");
nickLabel = new JLabel(" Nick : ");
nickTf = new JTextField(10);
bannerLabel = new JLabel(bannerIcon);
loginField = new JTextField(15);
passField = new JPasswordField(15);
loginButton = new SRFButton("Login");
cancelButton = new SRFButton("Cancel");
midPanel.add(loginLabel);
midPanel.add(loginField);
midPanel.add(passLabel);
midPanel.add(passField);
midPanel.add(nickLabel);
midPanel.add(nickTf);
upPanel.add(bannerLabel);
downPanel.add(loginButton);
downPanel.add(cancelButton);
getContentPane().add(upPanel,"North");
getContentPane().add(midPanel,"Center");
getContentPane().add(downPanel,"South");
loginButton.addActionListener(this);
cancelButton.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
in_pass = new String(passField.getPassword());
in_user = loginField.getText();
in_nick = nickTf.getText();
if (ae.getSource()==loginButton){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn = DriverManager.getConnection("jdbc:odbc:ChatServerData");
st1 = cn.createStatement();
rest = st1.executeQuery("select user_password from customer where user_id ='"+in_user+"'");
while(rest.next()){
//user = rest.getString("user_id");
pass = rest.getString("user_password");

if(in_pass.equals(pass.toString())){
logedIn();
}else{
loginFailed();
}
}
st1.close();
cn.close();
}catch(Exception e){
System.out.println("Error : "+e);
}
}
if (ae.getSource()==cancelButton){
hide();
}
}
public void logedIn(){
CheckNick();
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}
new chat();
hide();
Main.LogedIn();
}
// it just jumbs to the following method
public void loginFailed(){
JOptionPane.showMessageDialog(this,"The Password You Provided is Incorrect,\nPlease Try again!.","Login...",JOptionPane.INFORMATION_MESSAGE);
}
public void CheckNick(){
// check if the nick is not a banned or bad nick (check in database)

// then check if the nick already exist in the database or not

}
public void InsertNick(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn = DriverManager.getConnection("jdbc:odbc:ChatServerData");
st1 = cn.createStatement();
String q ="Insert Into users_status values ('"+in_user+"','"+in_nick+"','"+true+"')";
st1.executeUpdate(q);
}catch(Exception e){
System.out.println("Error : "+e);
}
}
}
the above code jumps to the else method which shows the message login failed. when i print the password and user name that are exactly right. and works perfectly on jdk1.4, jdk1.5 .
Tell me that is some thing wrong with my code or it is a bug in jdk1.6

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bino_george
Offline
Joined: 2003-06-16

Hi,
I tried compiling your code and it looks like
it contains lots of missing references to classes
and methods. I tried replacing the SRFButton with
JButton but it still has other problems.

Login.java:98: cannot find symbol
symbol : class chat
location: class Login
new chat();
^
Login.java:100: cannot find symbol
symbol : variable Main
location: class Login
Main.LogedIn();
^

Can you provide a simplified testcase or send
me the full code ? I will look into this to
see if there is a regression.

Thanks,
Bino.

dburgess
Offline
Joined: 2008-01-14

Please forgive my butting in. I find that the following code shows this behaviour too (works in 5.0, gives an access violation in 6.0). I hope this helps.

The access violation seems to occur after a call to sun.jdbc.JdbcOdbc.driverConnect

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;

public class BQDummyApp
{
static Connection con;

public static void main(String[] args)
{
String url;
JFrame f = new JFrame("Dummy");
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
try
{
con.close();
}
catch (SQLException ex)
{
System.err.println("error closing.");
System.err.println(ex);
}

System.exit(0);
}
});

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException ex)
{
System.err.println("ClassNotFoundException: " +
ex.getMessage());
}

url = "jdbc:odbc:" + "2006becbase";

con = null;

try
{
con = DriverManager.getConnection(url,"Admin","");
}
catch (SQLException ex)
{
System.err.println("Cannot connect to this database.");
System.err.println(ex);
}

f.pack();
f.setVisible(true);
}

} // BQDummyApp