Good day,
Please check out the codes below, seems am stock with my "if else" control.
This is the concept....
i want to asign a secret code for every database input, but where the "Name" exit in the database, it only re-asign the old code.
on test-running, i noticed that
"if(myResult == d){...}" is always skipped when
"myResult == d" and when
"myResult != d". what is the problem?
public String createSceretCode(String myCode)
{
try
{
// Load the Driver(registers itself)
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver loaded");
}
catch(ClassNotFoundException cnfex)
{
JOptionPane.showMessageDialog(null,"The driver can not be loaded...",
"Driver Error!!!",JOptionPane.ERROR_MESSAGE);
}
try
{
// Connect to the database
con = DriverManager.getConnection("jdbc dbc:AccountDepartment","","");
System.out.println("Connected to database");
}
catch(SQLException sqlex)
{
JOptionPane.showMessageDialog(null,"Cannot connect to the database...",
"Connection Error!!!",JOptionPane.ERROR_MESSAGE);
}
try
{
stmt = con.createStatement();
String d = f1.getText();
System.out.println(d);
r = stmt.executeQuery("SELECT Name,SecretCode FROM Account WHERE Name = '" +d +"'");
System.out.println(d);
if(r.next())
myResult = r.getString("Name");
if(myResult == d)
{
System.out.println(d);
myCode = r.getString("SecretCode");
}
else
{
query = "SELECT * FROM code";
r = stmt.executeQuery(query);
if(r.next())
codee = Integer.parseInt(r.getString("CreateCode"));
System.out.println(codee);
System.out.println(query);
codee += 1;
myCode = "CTL-" +codee;
System.out.println(codee);
query = "UPDATE code SET CreateCode ='" +codee +"'";
stmt.executeUpdate(query);
}
stmt.close();
con.close();
}
catch(SQLException sqlex)
{
JOptionPane.showMessageDialog(null,"Cannot Create Secret Code because an Error has occurred.",
"Connection Error!!!",JOptionPane.ERROR_MESSAGE);
}
return myCode;
}
[ June 29, 2005: Message edited by: Bear Bibeault ]