Any sample program to fetch data with JSP from MySQL

Hi,
Anybody can you ple give me a sample code to fetch data from MySQL and show it.
Database server : localhost
Databasename : test
Database User : root
Database Password : (database have no password)
Table Name : category
Table column name : catName
I am trying the following code, but it gives error:
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
     org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
<%@ page import="java.sql.*" %>
<%
String connectionURL = "jdbc:mysql://localhost:3306/test";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>
<html><body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT * FROM category");
while (rs.next()) {
out.println(rs.getString("catName")+"<br>");
rs.close();
%>
</body></html>
any help is appreciated.
---Sujoy

Just replace the following code. I think it will work for u.
<%@ page import="java.sql.*" %>
<%
try{
String connectionURL = "jdbc:mysql://localhost:3306/test";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT * FROM category");
%>
<html><body>
<table>
<%
while(rs.next())
%>
<tr><td><%=rs.getString("catName")%></td></tr>
<%
%>
</table>
</body>
</html>
<%
rs.close();
statement.close();
connection.close();
catch(Exception e)
       e.printStackTrace();
finally()
  try{
   rs.close();
   statement.close();
   connection.close();
  catch(Exception e)
        e.printStackTrace();
%>

Similar Messages

  • Suggestion on using SwingThreads to fetch data with Stateless Sessin Beans

    Hi,
    I have developed a GUI application using Swing.
    Using this GUI user will be able to view data (Tabular representation)fetched from database using Stateless session beans. In the application there will be two tabs and data should be fetched based on filtering parameters like Id which is a combo box. So if the user changes the comboBox selection, the data should be updated in two tabs irrespective of current tab focus.
    Currently I'have not used any Threading concept while fetching data. I have made calls based on Tab focus. But plans to use SwingThread SwingUtilities class. But it has problems of asychronous communication. So if anyone has faced problems using swing thread for doing database access using stateless session beans can throw somelight on this to avoid problems which may come later.
    In simpler terms using Swing threads have to make two or three EJB calls and fetch data from database and update the Table data.
    Thanks.

    Your user response time should not necessarily increase. You could load your data for the selected tab first and update the display after each response. This is simply showing information as soon as it becomes available rather than waiting for the entire operation (2 remote calls) to complete.
    If you use 2 Threads you might get this anyway but should ensure that your EJB calls happen in parallel otherwise you should work out the best order for them yourself.
    I'm not sure I'd say that you'd get synchronisation issues. You might get data issues whereby, as you rightly say, one of your calls returns an error. This shouldn't cause too many problems but you will need to make sure you've got suitable error-handling code and the ability to convey errors to the user.
    Personally, if the calls were dependent on each other I'd make them one after another in the same Thread rather than trying to coordinate two concurrent remote calls.
    If you're worried about the overhead of two remote calls in series then you can always expose another stateless session bean method that will perform both calls (or however many you want) for you in one remote call, thereby cutting down the overhead and simplifying your client development.
    Hope this helps.

  • Unable to fetch Data with apps_query_role

    Hi Guru,
    There is some issue on fetching data with my database account i have apps_query_role i can fect the data from devlopemnet instance.
    which checked in devlopemnt instance:
    select * from all_directories
    I am getting data
    When doing same thing in prod i am getting no row selected. Please help here.

    Hi,
    it would be hard to guess the things.. Try to check the session_privs from your current session with prod,
    Try to check privs granted on directories to specific to your account or not.
    - Pavan Kumar N

  • Do you have any sample program for HRPIQ00AUTHORITY Badi [ urgent]

    do you have any sample program for HRPIQ00AUTHORITY Badi and would be appreciated if you have over t me.
    regards,
    jin dal

    Thanks for the help.

  • Any solution for preventing converted data (to excel) from crashing?

    Any solution for preventing converted data (to excel) from crashing - file crashes on a consistent basis.

    Hi Shrinivas,
    LabVIEW is getting bug fixes and new features with each version step.
    But new features also can bring new bugs - and not all bugs from older versions are fixed by now…
    The MixedSignalGraph is a beast of it's own and known to have bugs inside. The one you noticed now is probably one of those.
    So it's not your fault your VI terminates rather "unhappy", but most probably NI's fault. You can have a workaround as described in the last post.
    If I have to take same data from wire as you mentioned, I need to save the data in some variable
    No, you don't need any "variable"! THINK DATAFLOW: the wire is the variable!
    I have to write the data to excel file using report generation tool kit or some other way. … Please let me know if I can do it in some other easy methods. 
    It all depends on the datatype of your data. There are functions to save to spreadsheet files. You can save in binary files. You can create TDMS files , which can be read by Excel too. All those functions are really easy to use - you just have to look at the example VIs coming with LabVIEW!
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • In addition to the FormsCentral subscription charge ($152.87 including tax) I was billed about the same time for $15.93. I can't find any way to get in touch with anyone from Adobe. The phone number I'm supposed to call is cut off on my invoice. Can someo

    In addition to the FormsCentral subscription charge ($152.87 including tax) I was billed about the same time for $15.93. I can't find any way to get in touch with anyone from Adobe. The phone number I'm supposed to call is cut off on my invoice. Can someone respond ASAP? Thanks

    I have forwarded your request to the support team that should be able to resolve this issue for you quickly. Expect to hear from them shortly.
    Andrew

  • Is there any standard program or FM to configure mail from SAP?

    Hi Experts,
    Is there any standard program or FM to configure mail from SAP?
    Regards
    Ramesh V

    Hi Ramesh,
    PFB.
    You can use function SO_NEW_DOCUMENT_SEND_API1
    Have a look at URL-> http://sapr3.tripod.com/abap011.htm
    Check the below forum:
    http://www.geocities.com/mpioud/Z_EMAIL_ABAP_REPORT.html
    Regards,
    Faisal.

  • How to create table with jsp in mysql

    Hi, every one,
    I just want to know how to create a table with jsp in mysql, please.
    Thanks in advance

    I have got the same question. I tried to pass sql "Create table" statement, but the servlet engine (tomcat4) threw an error "could not manipulet statement.execute". It works for normal SQL select statement.
    Anyone got the same problem ? or got a solution for this ? someone told me that PHP can do it, but just want to get it works with JSP.

  • How to bulk import data into CQ5 from MySQL and file system

    Is there an easy way to bulk import data into CQ5 from MySQL and file system?  Some of the files are ~50MB each (instrument files).  There are a total of ~1,500 records spread over about 5 tables.
    Thanks

    What problem are you having writing it to a file?
    You can't use FORALL to write the data out to a file, you can only loop through the entries in the collection 1 by 1 and write them out to the file like that.
    FORALL can only be used for SQL statements.

  • Hi.I want to program a VI to configure Epix's PICXI D2X board and to take images. can anybody help me with any sample programs showing the functions used to configure and communicate with the board.Thanks.

    I am a student. Just started with Labview. hence, any sample VIs will be of real help to start with.

    You might be interested in this post:
    http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RNAME=ViewQuestion&HOID=506500000008000000D4700000&ECategory=Vision
    Best of luck.

  • Grouping Data with JSP or JSTL

    Hi All,
    I would like to ask a question about how I can group data in JSP. Essentially, I have a DataBean (extends ArrayList) that is being returned to my JSP. The ArrayList contains HashTables. Please note that the JSP assumes the data is returned in sorted order. This JSP is not responsible for sorting the data itself.
    [UPDATED EXAMPLE]
    For example, here is what the data might look like:
    Column A Column B Column C
    1 2 3
    1 15 20
    4 5 6
    4 99 66
    7 8 9
    10 11 12
    Here is how I would use my DataBean:
    String column1Name =bundle.getString(�columnA.title�);
    String column2Name =bundle.getString("columnB.title");
    String column3Name =bundle.getString("columnC.title");
    /* Loop through the bean. */
    for (int i=1;i<myDataBean.size();i++) {
    Hashtable reportRow=myDataBean.get(i);
    String column1Value=reportRow.get(Constants.COLUMNA);
    String column2Value=reportRow.get(Constants.COLUMNB);
    String column3Value=reportRow.get(Constants.COLUMNC);
    }Question
    If I want to change my layout/display to group by a particular column. How would I do that without changing the data structure that is running my current DataBean? Below is an example of grouping by the values in ColumnA.
    ColumnA: 1
    ColumnB ColumnC
    2 3
    15 20
    ColumnA: 4
    ColumnB ColumnC
    5 6
    99 66
    ColumnA: 7
    ColumnB ColumnC
    8 9
    ColumnA: 10
    ColumnB ColumnC
    11 12
    Your help is very much appreciated.
    Thanks!

    Just curious, do people find my question unclear? Can I help clarify any points?

  • Sample programs in Oracle Data Mining 10.1

    I have installed Oracle Data Mining 10.1.
    But I can't find the sample programs located in \dm\demo.
    How can I find these sample programs??
    Help me. Thx.

    I think they are installed during the installation of the Companion Cd of Oracle 10g.
    Simon

  • Exporting original creation dates with images from IPhoto 08

    Hello experts: I'm trying to create an archival, file-based image storage structure outside of iPhoto 08 (7.1.5). When I use File/Export to add images to the archival file in the Finder, the resulting image is fine but the original creation date of the image is lost, being changed to a different, and later, date. I've tried ways of moving the image, including dragging, cut and paste, transferring the image to Aperture 2 and exporting, etc. and there's no joy. Any suggestions other than manual redos with A Better Finder Rename 8?
    Sierra!Hiker

    Why do you think that the date is lost?
    I suspect that you are confusing photos dates (stored in the EXIF data of the photo and viewable by photo programs) with the file dates which are viewable in file programs like the finder - the finder does not look at photo dates (EXIF) and photo programs do not look at the file date unless there is no EXIF data - the the file date is used by iPhoto
    LN

  • Can I acquire data with VB from my DAQCard without using Measurment Studio?

    I have the Measurement and Automation Software on my computer and VisualBasic.NET. Do I need any other software if I am receiving 2 analog signals and outputing 1 analog signal on my NI DAQCard-6024E PCMCIA?

    The short answer is yes, you can acquire data with VB.NET from your DAQCard without using Measurement Studio.
    There are a variety of ways to do it. All of them require that you install either the Traditional DAQ driver or the DAQmx driver in addition to Measurement and Automation Explorer. The DAQ drivers are included on a CD or CDs with your hardware. They are also available on the quarterly National Instruments Device Driver CD.
    1) You can use the Measurement Studio DAQmx .NET API. This is far and away the easiest API to use to program DAQ cards in VB.NET and C#. This API is included in the DAQ installer and does not require you to purchase Measurement Studio. However, without Measurement Studio you do not get the benefit of the DAQ Assistant integrated into Visual Studio .NET. The DAQ Assistant, when integrated into Visual Studio .NET, allows you to graphically configure your DAQ tasks, generates the code you need to configure your tasks, and generates a .NET user control (with user interface) that demonstrates how you use the tasks that you created. The caveat to this approach is that PCMCIA cards are not directly supported under DAQmx 7.0. There is, however, a beta versin of DAQmx PCMCIA support as described in this KB article.
    2) You can use the .NET P/Invoke services to call the Traditional DAQ or DAQmx C API directly. See MSDN for more information about P/Invoke. If you choose the DAQmx API, you will need to install the beta of the PCMCIA support as described in this KB article. National Instruments does not provide any examples, language-specific documentation, or code generation for this method. You'll need to look at the C API documentation to see what to do.
    3) You can use the Measurement Studio Traditional DAQ ActiveX controls. These are included in the DAQ installer and do not require you to purchase Measurement Studio.
    The absolute quickest and easiest way to get started using an NI-DAQ card in VB.NET is through the DAQ Assistant and Measurement Studio Professional or Enterprise edition.
    Your next best approach is to use the native .NET DAQmx API. This API was designed from the ground up to support .NET languages. There are examples written in VB.NET to help you get started.
    If for some reason, you don't want to use the native .NET API (or your hardware is not supported under DAQmx), whether you use P/Invoke or the ActiveX controls is a toss-up. It depends mostly on whether you are already familiar with the C API or the ActiveX API.
    David Rohacek
    National Instruments

  • Building HTML page with JSP from different applications

              Hi,
              we need to build a HTML page with 2 JSPs. If both JSP were in the same Application
              (Weblogic 8,1) there is no problem. But I have to use JSPs from differents web
              applications, each JSP is in different war files.
              How can I compose this page? How can I management the request object?
              thanks
              

    Your program print the whole jsp source code??
    This is your web server configuration problem.
    Your web server handle your jsp page like text file only.

Maybe you are looking for

  • ICON in the detail line of a Infoblock (Factsheet) in CRM

    Hi folks Has anyone out there tried to display an ICON in a factsheet in the Bussines Partner Cockpit In the class where I create a Infoblock for the Factsheet, I want to display the ICON_MESSAGE_WARNING_SMALL (@8R@) in front of the name of a Contact

  • Report notification to users

    Can reports notify you when it has been completed or a group of users. Please respond directly to my email if possible. [email protected]

  • How Oracle tables can be used to display Chinese/Japanese characters

    If anyone knows how to display Chinese/Japanese characters from Oracle tables please reply this email. Thanks. Regards, Preston

  • TCP/IP matters

    Hi to all I was just wondering if it is necessary to close TCP/IP connection after an error(e.g connection lost) had occured. Is it ok if I just reopen another connection to the same IP and port without closing the existing connection(that connection

  • Downloading an order using a different e-mail

    My colleague registered his information, including e-mail, when ordering and paying for the RoboHelp 9 upgrade. However, it is to be installed on my pc, and I want to use my previously registered Adobe ID to download. But when I log in with my ID the