473,606 Members | 2,109 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 4631
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
4183
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 PHP/MySql site. From one command button (or similar) in the Access application.
1
1706
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 records. All these procedures have sped up my work. Now, if I work with PHPMyAdmin, I find that I lose...
1
2436
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
2704
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
6251
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 it would be interesting to look at the queries Access throws at MySQL through the ODBC link, so I...
2
11613
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. Add dbi inclusion. (pretty straight forward, like an “include” in C or “import” in Java use...
0
1456
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 tweaking to work with MySQL. Any advice would be great. Thanks Function HelpDesc(HelpFrm As...
0
1492
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 and Table3 of 4,462 there were 58 corrupt. The MySQL database has been in use for only three years....
1
2396
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"; $Hostname = "localhost"; $MySQLConnection = mysql_connect($Hostname, $Username, $Password) ...
0
7939
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8432
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8428
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8078
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
5456
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3964
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2442
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1548
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1285
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.