not able to access records from mysql database using jsp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • menmysql
    New Member
    • Mar 2007
    • 53

    not able to access records from mysql database using jsp

    i am not bale to solve this problem since two weeks

    i am trying to access records from mysql database using jsp. inside this jsp program i wrote all my JDBC code. it is working very nicely and displaying records.

    now i wrote all the JDBC code in .java and i am accessing that code in jsp file. but this time i am getting only exceptions not records. i am keeping my programs here. please crosscheck once and tell where i am wrong

    code

    connect.java
    -------------------
    Code:
    
    package connection;
    import java.sql.DriverManager;
    import java.sql.Connection;
    import java.io.*;
    public class connect 
    {
    Connection conn;
    public connect()
    {
    try{
    Class.forName("com.mysql.jdbc.Driver");
    }
    catch(Exception e)
    {
    System.out.println(e);
    }
    }
    public Connection getConnection()
    {
    try{
    conn=DriverManager.getConnection("mysql:mysql://localhost/hello","root","root");
    }catch(Exception e)
    {
    System.out.println(e);
    }
    return conn;
    }
    }
    ---------------------------------------------------------------
    SqlBean.java
    ---------------
    Code:
    package sq;
     
    import connection.*;
    import java.sql.*;
     
    public class SqlBean
    {
    	Connection con=null;
     
    	public SqlBean()
    	{
    	connect c=new connect();
    	con=c.getConnection();
    	}
     
    	// it is used to select the records based on Query
    	public ResultSet selection(String query)
    	{
    	ResultSet rs=null;
    	try
    	{
    		Statement st=con.createStatement();
    		rs=st.executeQuery(query);
    		//return rs;
    	}
    	catch(Exception e)
    	{
    		System.out.println(e);
    	}
     
    	return rs; 
    	}
     
    }
    --------------------------------------------------

    test.jsp
    -------------
    Code:
    <%@ page import="java.sql.*" session="false" %>
    <jsp:useBean id="s" class="sq.SqlBean" scope="page" >
    <% ResultSet rs=s.selection("select name from how");
     
    while ( rs.next() )
    { 
    	out.println(rs.getString(1)); 
    } 
    %>
    </jsp:useBean>
    and the exceptions what i am getting is

    Code:
    HTTP Status 500 - 
     
    --------------------------------------------------------------------------------
     
    type Exception report
     
    message 
     
    description The server encountered an internal error () that prevented it from fulfilling this request.
     
    exception 
     
    org.apache.jasper.JasperException
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
     
     
    root cause 
     
    java.lang.NullPointerException
    	org.apache.jsp.test_jsp._jspService(test_jsp.java:57)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
     
     
    note The full stack trace of the root cause is available in the Tomcat logs.
     
     
    --------------------------------------------------------------------------------
     
    Apache Tomcat/5.0.16
    waiting for your valuable replys
  • hirak1984
    Contributor
    • Jan 2007
    • 316

    #2
    where is your method connect()
    getting called?

    Comment

    • menmysql
      New Member
      • Mar 2007
      • 53

      #3
      itis there at connection package (inside first program what i posted). i am getting records using this copd only when embeded this code inside jsp program. i amgetting this error while using .class files.


      Originally posted by hirak1984
      where is your method connect()
      getting called?

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        In the future please use a good thread title. Here is the appropriate snippet from the FAQ that you should have read.

        Using a good, clear thread title is important. The reasons for this are:

        * We want this site to grow, many of our new members find the site using a search engine, by using a good thread title you will help us grow the site by helping us get better search engine rankings.
        * Using a good title will benefit you too because other members of the forum will be less likely to skip over your thread and it allows the experts to quickly scan through the forum for questions they know the answer to.
        * If the threads are well titled it allows other users to easily see if there have been any threads that could be relevant to their own current problem.
        * It is in everybody's best interests to post properly titled threads as the more time the moderators have to spend on managing titles the less time they have available to give answers to the questions posed.

        Comment

        • menmysql
          New Member
          • Mar 2007
          • 53

          #5
          thanks for your good sugessions

          actually i want to keep the title as "not able to access records from mysql database using jsp" but by mistake i did not typed "not able to". is it possible to edit my title. if possible tell me ow to edit


          regards








          Originally posted by RedSon
          In the future please use a good thread title. Here is the appropriate snippet from the FAQ that you should have read.

          Using a good, clear thread title is important. The reasons for this are:

          * We want this site to grow, many of our new members find the site using a search engine, by using a good thread title you will help us grow the site by helping us get better search engine rankings.
          * Using a good title will benefit you too because other members of the forum will be less likely to skip over your thread and it allows the experts to quickly scan through the forum for questions they know the answer to.
          * If the threads are well titled it allows other users to easily see if there have been any threads that could be relevant to their own current problem.
          * It is in everybody's best interests to post properly titled threads as the more time the moderators have to spend on managing titles the less time they have available to give answers to the questions posed.

          Comment

          • RedSon
            Recognized Expert Expert
            • Jan 2007
            • 4980

            #6
            Originally posted by menmysql
            thanks for your good sugessions

            actually i want to keep the title as "not able to access records from mysql database using jsp" but by mistake i did not typed "not able to". is it possible to edit my title. if possible tell me ow to edit


            regards
            Done .

            Comment

            • menmysql
              New Member
              • Mar 2007
              • 53

              #7
              no one is there to help me regarding this problem

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by menmysql
                no one is there to help me regarding this problem
                Well, I don't want to disappoint you but the general opinion is that you should
                keep JSPs and databases apart from each other as much as possible. JSPs
                are just for view generation. Your servlets and beans should take care of the
                database handling.

                kind regards,

                Jos

                Comment

                • pcrnarra
                  New Member
                  • May 2007
                  • 1

                  #9
                  DriverManager.g etConnection("j dbc:mysql://localhost:3306/hello",''userna me","password") ;
                  type the port number also..

                  otherwise use this URL:

                  jdbc:mysql:///hello where hello is ur schema name
                  Last edited by pcrnarra; May 30 '07, 07:26 AM. Reason: corrected args

                  Comment

                  Working...