www.webdeveloper.com
Results 1 to 14 of 14

Thread: Issue with JDBC Connection

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Posts
    11

    Issue with JDBC Connection

    hi.....

    I have some issues to connect with the Database. I m using Oracle....
    I have a Login page page..when I type the user name and password it will go to the Home.jsp page. It is workingfine at my end.. However, when i tried in client machine, it wont. I have given some log files to check where the issue persists.. It fails at DriverManager.getConnection("jdbcracle:thin:@......)..Previously it works fine there... didnt get any error message. It hangs there.....When I click on Login button, it tries to load the page and hangs there.....it prints the logs given before the getConnection......
    whether it is an issue with Oacle JDBC Driver?????
    Help me.......

    Fins

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    well what error is it giving? unable to find class?

  3. #3
    Join Date
    Nov 2006
    Posts
    11
    Didnt get any reply. Browser is trying to load and it hangs there.....I waited for more than 10 mts. thn lso browser is trying to load....i have used a TestJdbc java file to check the JDBC driver. first of all I tried that java file in my PC. It works fine and got the output if the Connection is there.... But in client machine, it wont give ny result....the same thing.......what haapened in the Browser..

  4. #4
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    I'm confused. Are you using servlets/jsps or something like that? How do you execute it on your client and over the browser, basically?

    You need make sure that your classpath has the oracle jdbc drivers in it. what web server are you using?

  5. #5
    Join Date
    Nov 2006
    Posts
    11
    Ok .Will explain it clearly. I am using JSP. I have a Login.jsp page. Here I will provide the user name and password. And it will goes to CheckLogin.jsp. Here the databse connetion comes. Using Oracle database. and Jdbc thin driver. but it wont connet to the Database.

    I have given log files to check where the issue persists..
    Ex:
    Log("1st...");
    Class.forName(".....);
    Log("2nd...");
    Connection con=DriverManager.getConnection("....");
    Log("3rd....");

    Like that I have provided..I have used Log4J for printing the log file.
    After I run the jsp program, it prints 1st aand 2nd in the log file.

    After that, it didnt print the 3rd or what the log I provided in the catch block.

    After the Class.forName (), there is some issue with DriverManager.getConnetion....it is working at my end....
    the issue is with only the client system ...Previously it was working fine in the client system also....
    When I enter the user name and password in the Browser, it will goes to the CheckLogin.jsp and trying to load and then nothing happens. Trying to read....
    Didnt get any error message. Browser trying load and I have waited for more than 10 mts...then also the same status ...trying to read....

    there is no issue with the code as it is working fine in my end and i tried it in a testing machine also.. There also it works fine... But in client system it is not working.. previously it was working there without any issue....So whether it is anissue with the JDBC driver or Database????
    How can I install the Oracle Jdbc thin Driver??? From where I can downlaod it????

    Plzz help mee...

    thanx for your reply.................

  6. #6
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    It sounds like your client system has a different classpath than you do.

    You can probably download the oracle jdbc from oracle.com.

  7. #7
    Join Date
    Nov 2006
    Posts
    11
    Previously it was working fine....so i think it is not the issue with the classpath...

  8. #8
    Join Date
    Aug 2006
    Location
    Michigan
    Posts
    1,046
    Here is something I have used

    Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>
    <%! Connection con=null; %>
    <%!Statement st = null;%>
    <%!ResultSet rs = null;%>
    
    
    <html>
    <head><title>This is a JSP/DBConnect Example</title></head>
    <body>
    
    <%
    	out.println("Query Output<br><br>");
    
    	try {
    		Class.forName("com.mysql.jdbc.Driver").newInstance(); //Add your driver here
    	} catch (ClassNotFoundException ce) {
    		out.println(ce);
    	}
    
    	try {
    		con = DriverManager.getConnection(
    		"jdbc:mysql://localhost/JSP", "user_name", "User_pass");
    		st = con.createStatement();
    		rs = st.executeQuery("SELECT * FROM user");
    		while (rs.next()) {
    
    			int uid = rs.getInt(1);
    			String lName = rs.getString(3);
    			String fName = rs.getString(2);
    			out.println(uid + " " + lName + " " + fName + "<br>");
    
    		} // end of while
    			
    		rs.close();
    		st.close();
    		con.close();
    
    	} catch (SQLException exception) {
    		out.println("<!--");
    		StringWriter sw = new StringWriter();
    		PrintWriter pw = new PrintWriter(sw);
    		exception.printStackTrace(pw);
    		out.print(sw);
    		sw.close();
    		pw.close();
    		out.println("-->");
    
    	}
    %>
    
    <%
        if (request.getHeader("HTTP_X_FORWARDED_FOR") == null) {
            String ipaddress = request.getRemoteAddr();
            out.println("Your IP is:" + ipaddress + "<br>" + "Proxy Status: NO");
        } else {
            String ipaddress = request.getHeader("HTTP_X_FORWARDED_FOR");
            out.println("Your IP is:" + ipaddress + "<br>" + "Proxy Status: YES");
        }
    %>
    </body>
    </html>
    I am connecting to a MySQL DB using xampp for testing. This is a DBConnect.jsp test file

  9. #9
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,136
    Post the complete error before I jump to conclusions..:-)
    Last edited by Khalid Ali; 12-18-2006 at 03:18 PM.
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  10. #10
    Join Date
    Nov 2006
    Posts
    11
    thnx for your reply.

    I have tried a JdbcCheckUp.java to check the Driver connection. It is workin at my end.. But when I compiled in client machine, didnt work.....
    when I provide database, user name and password, it tries to check and nothing happens.....tryin..trying...after10 mts also...its trying....didnt get any error message or anything....it wont exit from the Command Prompt or didnt show any error message.......

    Here I provided the JdbcCheckUp.java


    /*
    * This sample can be used to check the JDBC installation.
    * Just run it and provide the connect information. It will select
    * "Hello World" from the database.
    *
    * note: jdk1.2 is recommanded. jdk1.1 will also work
    */

    // You need to import the java.sql package to use JDBC
    import java.sql.*;

    // We import java.io to be able to read from the command line
    import java.io.*;

    class JdbcCheckup
    {
    public static void main (String args [])
    throws SQLException, IOException
    {
    // Load the Oracle JDBC driver
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

    // Prompt the user for connect information
    System.out.println ("Please enter information to test connection to the database");
    String user;
    String password;
    String database;

    user = readEntry ("user: ");
    int slash_index = user.indexOf ('/');
    if (slash_index != -1)
    {
    password = user.substring (slash_index + 1);
    user = user.substring (0, slash_index);
    }
    else
    password = readEntry ("password: ");
    database = readEntry ("database (a TNSNAME entry, name-value pairs): ");

    System.out.print ("Connecting to the database...");
    System.out.flush ();

    // Connect to the database
    // You can put a database name after the @ sign in the connection URL.

    System.out.println ("Connecting...");
    Connection conn =
    DriverManager.getConnection ("jdbcracleci8:@" + database,
    user, password);

    System.out.println ("connected.");

    // Create a statement
    Statement stmt = conn.createStatement ();

    // Do the SQL "Hello World" thing
    ResultSet rset = stmt.executeQuery ("select 'Hello World' from dual");

    while (rset.next ())
    System.out.println (rset.getString (1));

    System.out.println ("Your JDBC installation is correct.");

    // close the resultSet
    rset.close();

    // Close the statement
    stmt.close();

    // Close the connection
    conn.close();
    }

    // Utility function to read a line from standard input
    static String readEntry (String prompt)
    {
    try
    {
    StringBuffer buffer = new StringBuffer ();
    System.out.print (prompt);
    System.out.flush ();
    int c = System.in.read ();
    while (c != '\n' && c != -1)
    {
    buffer.append ((char)c);
    c = System.in.read ();
    }
    return buffer.toString ().trim ();
    }
    catch (IOException e)
    {
    return "";
    }
    }
    }

  11. #11
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,136
    sorry can not really go through all of the code, do 1 thing for me. Put debugging statements at
    1.once the driver class is loaded
    2.connections is created
    3. query is run
    4. and the after the the result set completes the loop
    and see which part hangs it. post your results
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  12. #12
    Join Date
    Nov 2006
    Posts
    11
    The above Java file I used for checking the Jdbc connection only. Actually, I am using a jsp page....There I got issue. In that I have provided log files to check where the issue persists(log4J).....
    I have provided log files before and after the DriverManager.getConnection()....Also, in try catch block.....

    It prints log files till the DriverManager.getConnection()...ddnt print no log files after the getConnection().........

    and I understand that it fails on DriverManager.getConnection("....");.....So to check the Jdbc connection, I have used the JdbcCheck.java file. there also I got the issue...only in client machine.....


    whether it should be the issue with JdbcDriver or ?????
    As it works fine previously, it might not be the issue with the classpath.

    thnx for r reply....

  13. #13
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,136
    It can not be issue with the drivers (unless I misunderstood something). all jsp code is processed on the server. not at the client machine. so your issue is server related and its the issue where your server side code resides. your connection url should look like the one below
    "jdbcracleci8:@hostaddress:1521:SID", "userName", "password"
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  14. #14
    Join Date
    Nov 2006
    Posts
    11
    i think some misunderstanding in our reply.....

    what the things we have installed or configured in our client's machine(for whom we have done this project-server) and the machine at my end are same.....it was workin fine at both the end previously....one week before the issue arises......they are not able to login to the home page....so we checked in our end...its working.....and thn we checked in our client's server machine...it is not workin.....

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles