473,322 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 4618
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

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

Similar topics

11
by: Mike MacSween | last post by:
My client has an MS Access database application on her local machine. I have full access to that in terms of changing the design. I've got a simple PHP/MySql application on shared hosting, so no...
1
by: bettina | last post by:
I have exported my old Access database to MySQL. I am used to using the possibilities of Access to retrieve, for example, for a definite column, the values in a column of another table (through a...
1
by: gordon.dtr | last post by:
Hi, Has anyone had this problem ? I am using MySQL ODBC 3.51 Driver, with MS Access 2003 and MySQL 4.1.11 standard log. I created my tables in MS Access, then exported them via ODBC to an...
2
by: David | last post by:
Hi, Has anyone had this problem ? I am using MySQL ODBC 3.51 Driver, with MS Access 2003 and MySQL 4.1.11 standard log. I created my tables in MS Access, then exported them via ODBC to an...
6
by: onnodb | last post by:
Hi all, While working on an Access UI to a MySQL database (which should be a reasonable, low-cost, flexible interface to the DB, better than web-based, much less costly than a full-fledged .NET...
2
by: gmccammon | last post by:
I am working on a class assignment where I have to connect to an MS Access database. The perl script is contained in a separate file *.pl I went into Control panel/ODBC/ and selected Microsoft...
0
by: John Kirkpatrick | last post by:
Hi all, I am having difficulty displaying records on a frontend MS Access 2000 form using a MySQL backend. The following code works well with the Jet database engine but doesn't work properly...
0
by: elg | last post by:
Out of interest: instead of going from Jet to MySQL I have installed one of my systems to replace an existing MySQL package. So it's MySQL to Jet4 (AC2000) In three MySQL tables the following...
1
by: chanshaw | last post by:
Alright so I got php running and installed i have mysql running and installed the thing im having a hard time with is having the php to call information from the mysql database. Im on Windows Vista...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.