Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2010
    Posts
    38
    Rep Power
    0

    Default 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: {

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,854
    Rep Power
    19

    Default

    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

  1. Problem with database connection
    By mainy in forum New To Java
    Replies: 3
    Last Post: 08-07-2009, 11:43 PM
  2. URL connection problem
    By rajeshgubba in forum New To Java
    Replies: 8
    Last Post: 04-23-2009, 06:22 PM
  3. Too many Connection Problem Plz Help
    By shuvra_pan in forum Advanced Java
    Replies: 3
    Last Post: 03-17-2009, 01:42 PM
  4. small problem in connection
    By BsBs in forum CLDC and MIDP
    Replies: 1
    Last Post: 01-27-2009, 06:03 AM
  5. connection problem
    By subash in forum JDBC
    Replies: 5
    Last Post: 04-22-2008, 09:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •