Hello
I am trying to login thru JSP, Web Server is Tomcat & database is sqlserver2000. After filling user, password & pressing submit button,error message is as follows :
cannot resolve symbol
symbol : variable connection
location: class org.apache.jsp.verifyuser_jsp
Statement statement = connection.createStatement();
This is the code :
<BODY>
<% String user = request.getParameter("user");%>
<% String pwd = request.getParameter("pwd");%>
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection(
"jdbc:odbc:DEVELOPER1","sa","");
System.out.println("database connected");
Statement statement = connection.createStatement();
}
String query1 = "SELECT Username, Password FROM login WHERE Username = '"+user+"' AND Password = '"+pwd+"'";
ResultSet p = statement.executeQuery(query1);
while (p.next())
{
String Puser = p.getString("Username");
String Ppass = p.getString("Password");
}
if (user.equals("Puser") && pwd.equals("Ppass"))
%>
<jsp:forward page = "welcome.jsp"/>
<% else { %>
<h3>Invalid username or password</h3>
<% }
connection.close();
catch (Exception e)
{
out.println(e.getMessage());
%>
<h3>error in accessing database</h3>
<% }
%>
</BODY>
what's wrong?
-
Login thru JSP not working? (5 messages)
- Posted by: p s
- Posted on: April 26 2004 04:51 EDT
Threaded Messages (5)
- Login thru JSP not working? by Allen Chee on April 26 2004 05:30 EDT
- Login thru JSP not working? by p s on April 26 2004 06:01 EDT
- Login thru JSP not working? by Alex Pointer on April 26 2004 06:38 EDT
- Login thru JSP not working? by Senthil Chinnaiyan on April 26 2004 07:48 EDT
- Login thru JSP not working? by Sanjaya Ganesh on April 26 2004 23:38 EDT
-
Login thru JSP not working?[ Go to top ]
- Posted by: Allen Chee
- Posted on: April 26 2004 05:30 EDT
- in response to p s
Maybe you didn't add in the import tag at the beginning of the page:
<%@ page import="java.sql.*"%> -
Login thru JSP not working?[ Go to top ]
- Posted by: p s
- Posted on: April 26 2004 06:01 EDT
- in response to Allen Chee
<%@ page import="java.sql.*"%> is given even then its not working. -
Login thru JSP not working?[ Go to top ]
- Posted by: Alex Pointer
- Posted on: April 26 2004 06:38 EDT
- in response to p s
it looks like you do not have a catch statement after your try statement
try the following
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection(
"jdbc:odbc:DEVELOPER1","sa","");
System.out.println("database connected");
Statement statement = connection.createStatement();
}
catch (Exception ex) {
System.out.println(ex);
} -
Login thru JSP not working?[ Go to top ]
- Posted by: Senthil Chinnaiyan
- Posted on: April 26 2004 07:48 EDT
- in response to p s
Statement statement = connection.createStatement();
Remove this } and paste it after connection.close() statement.
}
Actually you are closing your connection after <jsp:forward>, the lines after <jsp:forward> element will not be executed. So, if you get welcome.jsp, your connection.close() statement will never be executed. So, close your connection as soon as you are done.
Thanks,
Senthil. -
Login thru JSP not working?[ Go to top ]
- Posted by: Sanjaya Ganesh
- Posted on: April 26 2004 23:38 EDT
- in response to p s
The "connection" variable you have will have visibility only inside the try{} block. Standard variable visibility problem.
-Sanjay