jdbc: : please help! its urgent

please help me out ,Its working successfully butinspite of right username and password in DataBase its showing

UR NOTa valid user... what alteration must be there in try block?

Connection con=null;

Statement st=null;

ResultSet rs=null;

try

{

con=DriverManager.getConnection("jdbc:mysql://localhost/userdetails","mysql","xxxx");

st=con.createStatement();

rs=st.executeQuery("select * from MyUser223 where uname='s1' and upass='s2'; ");

if (rs.next())

{

out.println("Valid user");

return;

}//if

}//try

catch(Exception e){out.println(e);}

finally{try{con.close();}catch(Exception e){}}

out.println("<center>Sorry UR not a valid user</center>");

}//service

[790 byte] By [junita] at [2007-11-26 15:55:19]
# 1
Check in the MySQL configuration whether the user is allowed to connect from the ip address from which the attempt is being made (MySQL restricts user access at least partially based upon where the connection is made from).
masijade.a at 2007-7-8 22:15:59 > top of Java-index,Java Essentials,New To Java...
# 2
> rs=st.executeQuery("select * from MyUser223 where uname='s1' and upass='s2'; "); Change the above line to ("select * from MyUSer223 where username="+"' s1' "+"and pass="+"'s2' ");
AnjanReddya at 2007-7-8 22:15:59 > top of Java-index,Java Essentials,New To Java...
# 3

> > rs=st.executeQuery("select * from MyUser223 where

> uname='s1' and upass='s2'; ");

>

>Change the above line to

> ("select * from MyUSer223 where username="+"' s1'

> "+"and pass="+"'s2' ");

Why would that make any difference? you could as well write a + between every 2 characters!

Peetzorea at 2007-7-8 22:15:59 > top of Java-index,Java Essentials,New To Java...
# 4
Another thing. Remove the ; from the end of your query statement. The Exception your getting might be coming from either the connection attempt or the execute attempt. You would no more if you added a printStacktrace or at least e.getMessage() in a println to your catch block.
masijade.a at 2007-7-8 22:15:59 > top of Java-index,Java Essentials,New To Java...
# 5
Maybe it prints that output because you haven't embedded the outputstatement in any try/catch block at all... Hadn't read the complete code because it wasn't clear at all without [code] tags...
Peetzorea at 2007-7-8 22:15:59 > top of Java-index,Java Essentials,New To Java...
# 6
Hah, you're right. Very hard to see when the stuff is not in code tags.Looks like another person in need of help with basic program flow.;-)
masijade.a at 2007-7-8 22:15:59 > top of Java-index,Java Essentials,New To Java...
# 7
i dont think your code works at all. You are catching the exception but not handling it. Try outputting the exception so you can see what the problem is. It will tell you if u have bad SQL etc.Ted.
ted_trippina at 2007-7-8 22:15:59 > top of Java-index,Java Essentials,New To Java...