Results 1 to 2 of 2
Thread: Connection problem
- 09-16-2010, 01:19 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
Connection problem
Connection.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
try
{
String ConnectionURL = "jdbc:oracle:thin:@localhost:1521:mydata";
//String DBName = "mydata";
String Driver_Package = "oracle.jdbc.driver.OracleDriver";
String UserName = "system";
String Password = "dharmit";
//Load the Oracle Driver
Class.forName(Driver_Package);
Connection conn = DriverManager.getConnection(ConnectionURL,UserName ,Password);
}
catch(Exception error)
{
out.println("Connection Problem");
}
%>
Process.jsp // Process.jsp file is in other folder..
<%@ page language="java" import="java.sql.*"%>
<%@ include file="../Include/Connection.jsp" %> // Connection file is in include folder.
<%
String User=request.getParameter("user");
String Pass=request.getParameter("pwd");
int Count_Record=0;
try
{
Statement Stat = conn.createStatement();
ResultSet rs = Stat.executeQuery("SELECT * from LOGIN WHERE USER_NAME='"+User+"' and PASSWORD='"+Pass+"'");
while(rs.next())
{
Count_Record = Count_Record + 1;
}
if(Count_Record == 1)
{
out.println("Success");
}
else
{
out.println("Failed");
}
}
catch(SQLException exception)
{
out.println(exception);
}
%>
Error :
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 11 in the jsp file: /Admin/Process.jsp
conn cannot be resolved
8: int Count_Record=0;
9: try
10: {
11: Statement Stat = conn.createStatement();
12: ResultSet rs = Stat.executeQuery("SELECT * from LOGIN WHERE USER_NAME='"+User+"' and PASSWORD='"+Pass+"'");
13: while(rs.next())
14: {
- 09-16-2010, 01:58 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
This is why these things really ought to be in proper Java classes, and called from a Servlet.
JSPs are for display...
Anyway, your conn object is declared inside the try/catch and consequently only visible withtin that try/catch block. If you take it out of the try/catch block you hit a whole load of problems around what if the connection has failed. I suppose you could use a flag, or check if the conn is null or something...
Or you could do the proper thing and do this elsewhere.
Similar Threads
-
Problem with database connection
By mainy in forum New To JavaReplies: 3Last Post: 08-07-2009, 11:43 PM -
URL connection problem
By rajeshgubba in forum New To JavaReplies: 8Last Post: 04-23-2009, 06:22 PM -
Too many Connection Problem Plz Help
By shuvra_pan in forum Advanced JavaReplies: 3Last Post: 03-17-2009, 01:42 PM -
small problem in connection
By BsBs in forum CLDC and MIDPReplies: 1Last Post: 01-27-2009, 06:03 AM -
connection problem
By subash in forum JDBCReplies: 5Last Post: 04-22-2008, 09:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks