473,545 Members | 2,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

not able to access records from mysql database using jsp

53 New Member
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 4626
hirak1984
316 Contributor
where is your method connect()
getting called?
Apr 9 '07 #2
menmysql
53 New Member
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 Recognized Expert Expert
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
menmysql
53 New Member
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 Recognized Expert Expert
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
menmysql
53 New Member
no one is there to help me regarding this problem
Apr 11 '07 #7
JosAH
11,448 Recognized Expert MVP
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
pcrnarra
1 New Member
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
May 30 '07 #9

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

Similar topics

11
4175
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 direct access to the db server. I'd like to give her the facility to export the information in her local Access application to the shared...
1
1702
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 SELECT....), or determine a range of values that are allowed. Also I have always copied & pasted similar records and then modified the pasted...
1
2433
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 externally hosted MySQL database (fasthosts) . I then import-linked
2
2695
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 externally hosted MySQL database (fasthosts) . I then import-linked
6
6249
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 app or so.... is it?), I tried measuring the bandwith consumed by the Access/MyODBC/MySQL link, which came out to be, er, quite high. I fancied...
2
11596
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 Access driver and identified the source name. I was looking at a previous post here and many things appear to be similar to my requirements. 1....
0
1454
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 using the MySQL backend database. All records are displayed on the form using the Jet, but only one record appears using MySQL. Perhaps it just needs some...
0
1486
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 records were so corrupted they just couldn't be saved. Table1 from 71,839 records there were 8,728 corrupt. Table2 from 10,105 there were 331 corrupt...
1
2391
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 Ultimate, I'm using iis7 here is the code of the php. <?php $Username = "Webuser"; $Password = "password"; $Database = "sample"; ...
0
7468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7423
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7757
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5329
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.