LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-08-2003, 07:34 AM   #1
dai
Member
 
Registered: May 2002
Location: Wales
Distribution: Slack 8.1, Gentoo 1.3a, Red Hat 7.3, Red Hat 7.2, Manrake 8.2
Posts: 328

Rep: Reputation: 30
result set Database problem


Hi all Basically Ive got anApplet communicating with a Servlet using Sockets and Objectstreams.

The servlet takes Data sent and uses it in an SQL query in order to check if data in an Access 2000 database is correct.

Once The query is complete I take the values out of the resultset and place them in variables (SQLname) SQLpass) both strings.

I now try comparing tese Strings to those used originally to get the Query results (those sent by the Applet). Everytime I do this however the if statement returns a False value, that is it states that the strings are differrent, (thier not Ive done System.out.println at Applet and Servlet and they are exactly the same). ANyway heres an Example of what I mean (without Applet Servlet communication, this also doesent work) please help!!!

Example
=========================

result = statement.executeQuery("SELECT * FROM Users WHERE username='david' And password='password';");



while (result.next())
{


String SQLname = result(1).getString();
String SQLpass =result.getString("password");
System.out.println ("Heres the username " +SQLname+" And the Password "+SQLpass);
}

statement.close();

con.close();

if (SQLname == "david") System.out.println("True");
else System.out.println("False");//Always false


// }

catch (SQLException e)
{
System.out.println("An SQL Exception of type " + e.getMessage()+" Occurred");
}
 
Old 04-08-2003, 08:41 AM   #2
dai
Member
 
Registered: May 2002
Location: Wales
Distribution: Slack 8.1, Gentoo 1.3a, Red Hat 7.3, Red Hat 7.2, Manrake 8.2
Posts: 328

Original Poster
Rep: Reputation: 30
Okay Ive sorted above problem out (used (&&&&.equals)) instead of ==

But new problem now I get a NullpointerException from this loop when usr/pass evaluate to correct (It does do System.out first but wont redirect to new URL)

if ((SQLusr.equals(name)) && (SQLpassword.equals(pass)))

{
System.out.println ("SQLusr is same as name see" +SQLusr+ " "+name);
try {
passwordURL = new URL("http://localhost:8080/website/main.htm");
}
catch (MalformedURLException e)
{
passwordURL = this.getDocumentBase();
}
System.out.println ("SQLpassword is same as pass see" +SQLpassword+ " "+pass);
getAppletContext().showDocument(passwordURL);


}

else
{
System.out.println ("User pass incorrect");
Connecttoserver.SQLError.setText("User Pass incorrect");

}
 
Old 04-10-2003, 03:01 AM   #3
acjt
Member
 
Registered: Dec 2002
Location: Australia
Distribution: Gentoo
Posts: 161

Rep: Reputation: 30
Where is your NullPointer? Ie. what line?
 
Old 04-10-2003, 06:45 AM   #4
dai
Member
 
Registered: May 2002
Location: Wales
Distribution: Slack 8.1, Gentoo 1.3a, Red Hat 7.3, Red Hat 7.2, Manrake 8.2
Posts: 328

Original Poster
Rep: Reputation: 30
Null pointer occurs on this line: -


passwordURL = new URL("http://localhost:8080/website/main.htm");


The link does exist as its on my local PC and I can browse it through tomcat using exact same URL line.
 
Old 04-11-2003, 02:36 AM   #5
acjt
Member
 
Registered: Dec 2002
Location: Australia
Distribution: Gentoo
Posts: 161

Rep: Reputation: 30
That does seem weird indeed. Have you stepped through it with a debugger to see what the JVM thinks the values of each of the variables are?
Also, I guess just to try something different, you could try something like this.
Code:
if ((SQLusr.equals(name)) && (SQLpassword.equals(pass))) {
  System.out.println ("SQLusr is same as name see"  +SQLusr+ " "+name);

  try {
    String urlLocation = new String("http://localhost:8080/website/main.htm");
    passwordURL = new URL(urlLocation);
  } catch (MalformedURLException e) {
    passwordURL = this.getDocumentBase();
  }

  System.out.println ("SQLpassword is same as pass see" +SQLpassword+ " "+pass);
  getAppletContext().showDocument(passwordURL);
} else {
  System.out.println ("User pass incorrect");
  Connecttoserver.SQLError.setText("User Pass incorrect");
}
This isn't really any different, but it might cause the compiler to spit out something different.
The other thing I notice (and obviously I don't have all the code here) is the line
Code:
Connecttoserver.SQLError.setText("User Pass incorrect");
You can get 2 NullPointers here, Connecttoserver and SQLError, unless you have initialised them before this code runs - of course.
 
Old 04-11-2003, 07:39 AM   #6
dai
Member
 
Registered: May 2002
Location: Wales
Distribution: Slack 8.1, Gentoo 1.3a, Red Hat 7.3, Red Hat 7.2, Manrake 8.2
Posts: 328

Original Poster
Rep: Reputation: 30
Cheers the use of a variable to store the URL I have allreadty tried (same problem)

SQLerror is a label initialised in the Connecttoserver class.

Heres my current code for this if-statement (with system.out.println to check if the URL is in fact null)

try{
if (SQLusr.equals(name))
{
if (SQLpassword.equals(pass))
{ System.out.println ("SQLusr is same as name see" +SQLusr+ " "+name);
try {
passwordURL = new URL("http://localhost:8080/website/main.htm");
System.out.println ("final URL" +passwordURL); //This line shows that passwordURL is in fact the correct String/URL. From here nothing else is outputted or occurrs
getAppletContext().showDocument(passwordURL);
System.out.println ("final URL" +passwordURL);
}
catch (MalformedURLException h)
{
System.out.println ("Malformed URL");
passwordURL = this.getDocumentBase();
}
System.out.println ("should have opened page" +passwordURL);
//System.out.println ("SQLusr is same as name see" +SQLusr+ " "+name);

//System.out.println ("SQLpassword is same as pass see" +SQLpassword+ " "+pass);
//this.getAppletContext().showDocument(passwordURL);

}


else
{
System.out.println ("User pass incorrect");
Connecttoserver.SQLError.setText("User Pass incorrect");

}
}
}
catch (Exception f)
{
//getAppletContext().showDocument(passwordURL);
}

Last edited by dai; 04-11-2003 at 07:41 AM.
 
Old 04-11-2003, 08:14 AM   #7
acjt
Member
 
Registered: Dec 2002
Location: Australia
Distribution: Gentoo
Posts: 161

Rep: Reputation: 30
Can you put in the logging when you run it??

Can you also put this in:
System.out.println(getAppletContext());

Last edited by acjt; 04-11-2003 at 08:17 AM.
 
Old 04-11-2003, 08:28 AM   #8
dai
Member
 
Registered: May 2002
Location: Wales
Distribution: Slack 8.1, Gentoo 1.3a, Red Hat 7.3, Red Hat 7.2, Manrake 8.2
Posts: 328

Original Poster
Rep: Reputation: 30
I'll log the output using the Java Console when I get home

I'll do the "system.out.println" also

I'll post results later (including the output in the Java Console)
 
Old 04-11-2003, 05:11 PM   #9
dai
Member
 
Registered: May 2002
Location: Wales
Distribution: Slack 8.1, Gentoo 1.3a, Red Hat 7.3, Red Hat 7.2, Manrake 8.2
Posts: 328

Original Poster
Rep: Reputation: 30
Heres the Output from Java console (Doesent get to output state of Url or geAppletContext())

Trace level set to 5: basic, net, security, ext, liveconnect ... completed.

Start URLnull

This is before Stream and is david

This is before Stream and is password

This is after writing to stream java.io.ObjectOutputStream@94d48

middle URLnull

Everything Worked

This is the input david password this show the object stream works and SQL Query worked

Servlet fine

SQLusrdavid

SQLpasswordpassword

namedavid

passpassword

Connecttoserver.tname.getText()david

Connecttoserver.tPass.getText()password

middle 2 URLnull

SQLusr is same as name seedavid david//This is in If statement(see below for actual code as it stands)


Code
==========================


try{
if (SQLusr.equals(name))
{
if (SQLpassword.equals(pass))
{ System.out.println ("SQLusr is same as name see" +SQLusr+ " "+name);
try {
passwordURL = new URL("http://localhost:8080/website/main.htm");
System.out.println(getAppletContext());
getAppletContext().showDocument(passwordURL);
System.out.println(getAppletContext());
System.out.println ("final URL" +passwordURL);
}
catch (MalformedURLException h)
{
System.out.println ("Malformed URL");
passwordURL = this.getDocumentBase();
}
System.out.println ("should have opened page" +passwordURL);
//System.out.println ("SQLusr is same as name see" +SQLusr+ " "+name);

//System.out.println ("SQLpassword is same as pass see" +SQLpassword+ " "+pass);
//this.getAppletContext().showDocument(passwordURL);

}


else
{
System.out.println ("User pass incorrect");
Connecttoserver.SQLError.setText("User Pass incorrect");

}
}
}
catch (Exception f)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Set up Database for Mythtv SHERB142 Fedora 2 06-08-2005 07:40 PM
problem transfering result of search to a dialog box JoannesX Programming 3 02-07-2005 05:59 AM
mozilla session problem (did search could not find result) exodist Linux - Software 2 02-29-2004 04:10 PM
how i can set my windows client to use my mysql server as database sandeepchau123 Linux - Networking 0 11-20-2003 06:34 AM
cp command problem..... unexpected result hamster Linux - General 2 04-10-2003 04:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration