Error showing when connecting to MySQL using servlet

This is my Program. (MySQL.java)
package coreservlets;
import java.sql.*;
public class MySQL {
     public static void main (String[] args) {
     String driver = "com.mysql.jdbc.Driver";
     String url = "jdbc:mysql://localhost/leave_app";
     String username = "";
     String password = "";
     showEmployeeTable(driver, url, username, password);
public static void showEmployeeTable(String driver,
String url,
String username,
String password)
try{
               Class.forName(driver);
Connection connection = DriverManager.getConnection(url, username, password);
               Statement statement = connection.createStatement();
               String query = "Select userid from userlogin";
               ResultSet resultSet = statement.executeQuery(query);
               while(resultSet.next()){
                    System.out.print(resultSet.getString("userid"));
               connection.close();
               } catch(ClassNotFoundException cnfe) {
                    System.err.println("Error loading driver: " + cnfe);
               } catch(SQLException sqle) {
                         System.err.println("Error with connection: " + sqle);
Error showing
java.lang.ClassCastException: coreservlets.MySQL cannot be cast to javax.servlet.Servlet
     org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:370)
     org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:134)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Could someone help me to resolve this bug?

Hi,
I think you have misunderstood me. What I'm trying to say is that your MySQL.java doesn't seems to be the root cause of the problem.
The way you invoke the MySQL.java. may be the cause of the problem.
As from your implementation, your MySQL.java seems to be a plain java application. However, it seems that you are trying to treat MySQL .java as a servlet.
My guess this that you wanted to do something like this:
class MySQL extends HttpServlet {
     public void doPost(..... ) {
          //the codes in the main method to be put in this method.
     public void doGet( ....) {
             doPost(....)
     //some of your other methods put here.
}For more information on how to write a servlet, you may visit http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/servlet.html

Similar Messages

  • Error occured when connect to MySql Databse in Dreamweaver

    Hello! I met a problem when connect to Mysql Databse in
    Dreamweaver
    Details:
    My Php Environment: Php 5.2.2+ MySql 5.0.4 + IIS 6.0 + DW IDE
    + WinXP SP2,
    All necessary sevice started(Actually I have never stopped
    any Windows service).
    Php installed (IIS + CGI) and tested successfully in DW
    MySql Installtion(Typical Install with extensions ) and
    configuration are both OK.
    Configuration Details:
    For configuration type, select Detailed Configuration.
    For server type, select Developer Machine
    For database usage, select Non-Transactional Database Only.
    For the number of concurrent connections, select Decision
    Support(DSS)/OLAP.
    For networking options, accept the default settings.
    For the default character set, accept the default setting.
    For the Windows options, select both options – Install
    As Windows Service, and Include Bin Directory in Windows Path.
    For security options, enter a root password and confirmed.
    And then I Created a database "mydb" with 3 tables inside by
    "MySql Command Line Client",
    ...... (Approach Obmit here)
    Open "MySql Command Line Client":
    Type >mysql Show Database mydb;
    Show a list with 3 tables(Created Successfully)
    Then In DW,
    Open my Php webpage,
    Then from Database Panel>MySql Connection,
    Connect Name:myconn
    Mysql Server:localhost
    Username:root (Right)
    Password:111111(Right)
    Database:mydb
    Click "OK", but when DW tried to connect to MySql database,
    then DW popuped an alert dialog says "HTTP Error Code 502 Bad
    Gateway",
    I don't know what this mean and how to solve this problem,
    hope any PHP and DW expert can help me, thank you very much.

    Phoenix Wang wrote:
    > Click "OK", but when DW try to connect to MySql
    database, then popup an alert
    > dialog says "HTTP Error Code 502 Bad Gateway",
    > I don't know what this mean and how to solve this
    problem, hope any PHP and DW
    > expert can help me, thank you very much.
    How have you set up the Testing server in your site
    definition?
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • I am getting "Fatal Error: null" when connection to P6v8.3.2 DB using P6 Integration API

    I am getting "Fatal Error: null" when connection to P6v8.3.2 DB using P6 Integration API.
    I can connect via P6 client using admin account but cannot connect using P6 API. If I provide invalid credentials it says that the credentials are incorrect. When correct credentials are provided, it comes up with the above error.
    Stacktrace is atteched.
    Please assist.
    Thanks
    Sunil

    Hi Sunil,
    In the absence of sample code it is difficult to identify the cause. If that is not possible, you can try logging SR with Oracle support.
    Regards,
    Sachin Gupta

  • When i start itune than error shows this ipod cannot be use because the required software  not  install

    when i start itune than error shows this ipod cannot be use because the required software  not  install

    Have you tried removing and then einstalling the Apple software:
    Removing and Reinstalling iTunes, QuickTime, and other software components for Windows XP

  • My iPhone shows error -50 when connect to iTunes

    my iPhone shows error -50 when connect to iTunes. What can i do?  What does it mean?

    http://support.apple.com/kb/TS1583

  • Error message when connecting to Itunes

    Keep getting this error message when connecting.
    [IMG]http://img813.imageshack.us/img813/2214/ipod.png[/IMG]
    I have uninstalled and reinstalled twice now.
    Its an Ipod Touch 8GB with front and back camera.
    Thanks

    If pic doesnt work it says
    "This Ipod cannot be used because the required software is not installed. Run the Itunes installer to remove Itunes, then install Itunes again."

  • I get an error message when I try to use share function on IPhoto. I get the triangle icon with an exclamation mark inside of it.

    I get an error message when I try to use the share function on iPhoto. When I try to share photos via email a triangle icon with an exclamation mark appears. Why can't I use share function?

    The ! turns up when iPhoto loses the connection between the thumbnail in the iPhoto Window and the file it represents.
    What version of iPhoto? Assuming 09 or later
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Repair Database. If that doesn't help, then try again, this time using Rebuild Database.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. (In Library Manager it's the FIle -> Rebuild command)
    This will create an entirely new library. It will then copy (or try to) your photos and all the associated metadata and versions to this new Library, and arrange it as close as it can to what you had in the damaged Library. It does this based on information it finds in the iPhoto sharing mechanism - but that means that things not shared won't be there, so no slideshows, books or calendars, for instance - but it should get all your events, albums and keywords, faces and places back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. 
    Regards
    TD 

  • Roland UM-ONE  CD-ROM does not mount on iMac OS 10.8.2 Roland driver for 10.8 installed as directed. No power ready light shows when connecting UM-ONE. System Profiler shows it, but not configured. Older UM-1X works fine. UM-ONE works on Dell Windows XP.

    UM-ONE
    Roland supplied CD-ROM does not mount or read by iMac OS 10.8.2, works with old TiBook and Dell laptop, however.
    Got latest driver from RolandUS.com (um_1mx8d_v100), installed as directed.
    No power ready light shows when connecting UM-ONE.
    System Profile shows it there, but not configured.
    With Audio MIDI Setup opened to MIDI Studio window, UM-ONE does not appear.
    Tried many things without success. Tried swapping UM-1X (formerly on Dell laptop) with UM-ONE. UM-ONE installed and worked there without any issues. MIDI instrument communicates fine.
    The UM-1X works without complaint and as expected when connected to any USB port on either the Dell or iMac, even a hub or keyboard port, just as it formerly had before changing operating systems, etc. It is old, but reliable.
    Upshot is, for now, that UM-1X works with either the Dell or the iMac, but is currently attached to the iMac. UM-ONE (2011 model) only works with the Dell (Windows XP).

    Same problem here! The only difference is that I'm using a MacBook pro 13 inch (2011)

  • Error: Unable to connect to database using connection_pool

    Hi experts
    I have created repository and reports on my windows machine using ODBC , Now i have tranfered this to on unix with OCI, But when i am connecting to my dtabase it is showng the error:
    Error: Unable to connect to database using connection_pool
    Please suggest how to resolve this..

    Have you install the Oracle client in your Unix server?

  • How to define target window when redirecting within frames using servlet?

    Howdy:
    Is there a way to define target window when redirecting within frames using servlets?
    How to do it in JSP as well?
    T.I.A.
    Oriental Spirit

    Your servlet (or JSP) can't decide where it is going to be displayed. The browser has already decided that when it makes the request to your servlet.

  • Error message when connecting to iTunes says my new iPad 4 can't be connected as it requires version 10.7 or later. Surely a new iPad already has the latest version, and if it doesn't how do I get it?

    Error message when connecting to iTunes says my new iPad 4 can't be connected as it requires version 10.7 or later. Surely a new iPad already has the latest version, and if it doesn't how do I get it?

    Not the iPad - your computer must be running iTunes 10.7 in order to sync. It has nothing to do with iTunes on the iPad.
    You can download iTunes for your computer here.
    http://www.apple.com/itunes/

  • Does anyone Know how to fix error 0xe8000065 when connecting the ipod touch 4g

    does anyone Know how to fix error 0xe8000065 when connecting the ipod touch 4g

    See:
    iPhone, iPad, iPod touch: Unknown error containing '0xE' when connecting

  • I want to install lightroom previously installed on a macbook on a new macbook. I get an error message when I try to use the same serial number. How can I install lightroom on my new mac?

    i want to install lightroom previously installed on a macbook on a new macbook. I get an error message when I try to use the same serial number. How can I install lightroom on my new mac?

    Oliver,
    Are you getting activation errors? As Ned stated , it is easier to troubleshoot if we have the specific type of error and error detail that you are getting.
    Here is some help on activation if this is the issue:
    https://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html
    Pattie

  • ITunes 10.7 unknown error -1500 when connect to wireless speaker. OS X 10.75  Any thoughts?

    iTunes 10.7 unknown error -1500 when connect to wireless speaker. OS X 10.75  Any thoughts?

    For reasons unknown I found copies of many of these tracks as 256 kbps .m4a files in my Trash. As such I was able to remove the existing 128 kbps .m4p (Purchased) files (but not deleting them from iCloud), add the 256 kbps .m4a files to iTunes and then Add to iCloud whereupon, the original 128 kbps listings with the download from iCloud link switched to 256 kbps (Purchased) files. For a few of the files I accidentally deleted the 128 kbps (Purchased) from iCloud and when I added the .m4a to iCloud they appeared as 256 kbps (Matched) songs instead. Not sure why the difference, but it worked for several of these problematic files. But I still don't understand why/where these .m4a versions came from as most of these purchased predated iTunes Plus (e.g., my original purchases were 128 kbps). My new list of recalcitrant files is:
    Anna Nalick: Breathe (iTunes SOTW)
    Coldplay: Parachutes (tracks 4 + 5)
    Dave Matthews Band: Stand Up (tracks 3-6, 11, 12)
    Feis: One Evening (iTunes SOTW)
    Future Leaders…: Let Me Out (iTunes SOTW)
    Hinder: Get Stoned (iTunes SOTW)
    Living Things: Ahead of the Lions (iTunes SOTW)
    Low Millions: Eleanor (iTunes SOTW)
    Spymob: Sitting Around Keeping Score (iTunes SOTW)
    As you can see, most of these are iTunes single of the week (SOTW) offerings, so I'm not too bothered about them.

  • Error code when signing in to use face time; 3121-2138-7457 any ideas to the problem?

    I recieve and error code when signing in to use facetime (3121-2138-7457) any information regarding how to correct this error code would be appreciated?

    There is no official public documentation of that alert as far as I know.
    If you're trying to sign in to FaceTime, try to sign in to iMessage in the Messages application, or vice versa.
    Otherwise, do as the alert directs. According to reports, you won't be charged for the support call if you select "Apple ID"—not the hardware model—as the product you're asking about, and cite the "customer code" in the alert as the "validation code" when you speak to the Apple representative.

Maybe you are looking for