472,119 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

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
-------------------
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. package connection;
  4. import java.sql.DriverManager;
  5. import java.sql.Connection;
  6. import java.io.*;
  7. public class connect 
  8. {
  9. Connection conn;
  10. public connect()
  11. {
  12. try{
  13. Class.forName("com.mysql.jdbc.Driver");
  14. }
  15. catch(Exception e)
  16. {
  17. System.out.println(e);
  18. }
  19. }
  20. public Connection getConnection()
  21. {
  22. try{
  23. conn=DriverManager.getConnection("mysql:mysql://localhost/hello","root","root");
  24. }catch(Exception e)
  25. {
  26. System.out.println(e);
  27. }
  28. return conn;
  29. }
  30. }
  31.  
---------------------------------------------------------------
SqlBean.java
---------------
Expand|Select|Wrap|Line Numbers
  1. package sq;
  2.  
  3. import connection.*;
  4. import java.sql.*;
  5.  
  6. public class SqlBean
  7. {
  8.     Connection con=null;
  9.  
  10.     public SqlBean()
  11.     {
  12.     connect c=new connect();
  13.     con=c.getConnection();
  14.     }
  15.  
  16.     // it is used to select the records based on Query
  17.     public ResultSet selection(String query)
  18.     {
  19.     ResultSet rs=null;
  20.     try
  21.     {
  22.         Statement st=con.createStatement();
  23.         rs=st.executeQuery(query);
  24.         //return rs;
  25.     }
  26.     catch(Exception e)
  27.     {
  28.         System.out.println(e);
  29.     }
  30.  
  31.     return rs; 
  32.     }
  33.  
  34. }
  35.  
--------------------------------------------------

test.jsp
-------------
Expand|Select|Wrap|Line Numbers
  1. <%@ page import="java.sql.*" session="false" %>
  2. <jsp:useBean id="s" class="sq.SqlBean" scope="page" >
  3. <% ResultSet rs=s.selection("select name from how");
  4.  
  5. while ( rs.next() )
  6.     out.println(rs.getString(1)); 
  7. %>
  8. </jsp:useBean>
  9.  
and the exceptions what i am getting is

Expand|Select|Wrap|Line Numbers
  1. HTTP Status 500 - 
  2.  
  3. --------------------------------------------------------------------------------
  4.  
  5. type Exception report
  6.  
  7. message 
  8.  
  9. description The server encountered an internal error () that prevented it from fulfilling this request.
  10.  
  11. exception 
  12.  
  13. org.apache.jasper.JasperException
  14.     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
  15.     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
  16.     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
  17.     javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
  18.  
  19.  
  20. root cause 
  21.  
  22. java.lang.NullPointerException
  23.     org.apache.jsp.test_jsp._jspService(test_jsp.java:57)
  24.     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
  25.     javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
  26.     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
  27.     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
  28.     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
  29.     javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
  30.  
  31.  
  32. note The full stack trace of the root cause is available in the Tomcat logs.
  33.  
  34.  
  35. --------------------------------------------------------------------------------
  36.  
  37. Apache Tomcat/5.0.16
  38.  
waiting for your valuable replys
Apr 9 '07 #1
8 4357
hirak1984
316 100+
where is your method connect()
getting called?
Apr 9 '07 #2
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.


where is your method connect()
getting called?
Apr 9 '07 #3
RedSon
5,000 Expert 4TB
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.
Apr 9 '07 #4
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








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.
Apr 9 '07 #5
RedSon
5,000 Expert 4TB
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 .
Apr 9 '07 #6
no one is there to help me regarding this problem
Apr 11 '07 #7
JosAH
11,448 Expert 8TB
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
Apr 11 '07 #8
DriverManager.getConnection("jdbc:mysql://localhost:3306/hello",''username","password");
type the port number also..

otherwise use this URL:

jdbc:mysql:///hello where hello is ur schema name
May 30 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by Mike MacSween | last post: by
1 post views Thread by bettina | last post: by
1 post views Thread by gordon.dtr | last post: by
reply views Thread by elg | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.