Servlet dos not connect to mysql

Hi all I have been since 2 days trying to figure out why my servlet does not connect to the database MySql. I have mysql installed and working properly and eclipse. Whenever i try to etabilish a connection i get the ClassNotFoundException for the com.mysql.jdbc.Driver, which is actually properly imported, the connector i'm using is the mysql-connector-java5.1.14 added properly as external jar so everything seems fine. here's my code
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String dbUrl="jdbc:mysql://localhost:3306/test"; String username="root"; String password="";
try { Class.forName("com.mysql.jdbc.Driver").newInstance(); conn=DriverManager.getConnection(dbUrl); System.out.println("Connected!");
} catch (SQLException e) { e.printStackTrace(); System.out.println("not connected");
} catch(ClassNotFoundException x){ x.printStackTrace();
} catch(Exception e){
e.printStackTrace(); }
}The stacktrace(part of):
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:375) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:164)i'm following the connection steps from a published java book and also in forums and tutorials i just see the same code, cannot figure out why that Exception comes. On a normal application which does not run on the server the Exception isn't thrown and the connection (in the exact same way) its successfull. Do you have any advice?

Try adding something like this to the top of your class as an test:
import com.mysql.jdbc.Driver.*
If the compiler produces an error for this line, your jdbc jar file isn't visible to your application (not in the classpath).
If your using and IDE such as Eclipse, you can add it to the classpath as follows:
Copy the jar file to the WEB_INF/lib folder of your project. Then right click on the project Icon in Eclipse, and then:
properties->java build path->libraries->add jars
Then select the jar file.
Oter IDEs probably have a simliar setup.

Similar Messages

  • Database error #2002 can not connect local mysql server to socket through '/var/run/mysqld/mysqld.sock'(2) on mac os x 10.9.2

    Dear Fellas:
    I received "database error #2002 can not connect local mysql server to socket through '/var/run/mysqld/mysqld.sock'(2)" on mac os x 10.9.2.
    mysql info:
    ps -ef | grep mysql
        0    66     1   0 11:06AM ??         0:00.04 /bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql
       74   225    66   0 11:06AM ??         0:02.50 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/Chuans-MacBook-Pro-2.local.err --pid-file=/usr/local/mysql/data/Chuans-MacBook-Pro-2.local.pid --socket=/var/run/mysqld/mysqld.sock
      501   952   947   0  3:52PM ttys000    0:00.00 grep mysql
    Please help!!

    Fascinated and guessing:
    Something related to sock(2) because that's not part of your copied info. I'm thinking you've doubled up on sockets and the second socket doesn't exist, meaning you should be connecting to the first socket "mysqld.sock" whether automatic or not.
    I've only used GUI tools on purpose, so does this mean you've already got MySQL running and you tried to launch it again manually? Perhaps you already have one instance of a db and you're trying to launch a second instance, and the two can't coexist with a single user local db?
    Assuming this is all local, I'd shut down the db service and restart it, out of hand. I've seen similar messages when I set the db to start up on boot, and it didn't finish shutting down when I tried to restart it manually. Usually the GUI won't let me turn it on because it reports it's already running, but in that case it hadn't finished performing what the GUI was reporting.
    Just speculating.

  • HT1937 my phone dose not connect to my laptop ir dose not synic to itunes too

    my phone dose not connect to my laptop ir dose not synic to itunes too

    look for a post called itunes not recognising iphone 4s device not able to sync by grimhmfc
    it worked for me
    hope this helps

  • Can NOT connect to Mysql

    Hi All
    Below is my code for a simple form which connects to Mysql. Problem is if I just connect to database and not have any other code (i.e Form) that works fine but when I try to connect with the form code, it gives me errors. why??? some help will be greatly appreciated thank you.
    Zed
    code
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Driver;
    public class PersonalInfo extends Frame {
    Connection conn=null;
    Panel Np = new Panel();
    Panel Sp = new Panel();
    public PersonalInfo(){
    NorthPanel();
    add(Np,BorderLayout.NORTH);
    SouthPanel();
    add(Sp,BorderLayout.SOUTH);
    public void NorthPanel(){
    Label LfirstName = new Label("First Name");
    TextField TfirstName = new TextField(20);
    Label LlastName =new Label("Last Name");
    TextField TlastName=new TextField(20);
    Np.setLayout(new GridLayout(2,1));
    Np.add(LfirstName);
    Np.add(TfirstName);
    Np.add(LlastName);
    Np.add(TlastName);
    public void SouthPanel(){
    Button Submit=new Button("Submit");
    Sp.add(Submit);
    Button Cancel = new Button("Cancel");
    Sp.add(Cancel);
    public static void connect(){
    System.out.println("MySQL Connect Example");
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "test";
    String userName = "c3031843";
    String password = "vw84a3";
    String driver = "com.mysql.jdbc.Driver";
    try {
    Statement stmt;
    ResultSet rs;
    Class.forName(driver).newInstance();
    Connection conn = DriverManager.getConnection(url+dbName,userName,password);
    System.out.println("URL: " + url);
    System.out.println("Connection: " + conn);
    System.out.println("Connected to the database");
    stmt = conn.createStatement();
    rs = stmt.executeQuery("SELECT * " + "from category");
    System.out.println("Display all results:");
    while(rs.next()){
    int Int= rs.getInt("cat_id");
    String name = rs.getString("category");
    System.out.println("\tid= " + Int + "\tstr = " + name);
    }//end while loop
    conn.close();
    System.out.println("Disconnected from database");
    catch (Exception e) {
    e.printStackTrace();
    public static void main (String[] args) {
    System.out.println("Personal information");
    PersonalInfo PerInfo = new PersonalInfo();
    PerInfo.setTitle("Personal Information");
    PerInfo.setSize(400,200);
    PerInfo.setVisible(true);
    connect();
    PerInfo.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    }Errors Code
    Personal information
    MySQL Connect Example
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at PersonalInfo.connect(PersonalInfo.java:52)
    at PersonalInfo.main(PersonalInfo.java:80)
    Process completed.

    Warnerja thanks for your reply, like I said if I don't use any other code and just use like this;
    import java.sql.*;
    public class MysqlConnectionTest {
    public static void main(String[] args) {
    System.out.println("MySQL Connect Example");
    Connection conn=null;
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "test";
    String driver = "com.mysql.jdbc.Driver";
    String userName = "c3031843";
    String password = "vw84a3";
    try {
         Statement stmt;
         ResultSet rs;
    Class.forName(driver).newInstance();
    conn = DriverManager.getConnection(url+dbName,userName,password);
    System.out.println("URL: " + url);
    System.out.println("Connection: " + conn);
    System.out.println("Connected to the database");
         stmt = conn.createStatement();
         rs = stmt.executeQuery("SELECT * " + "from category");
                    System.out.println("Display all results:");
          while(rs.next()){
            int Int= rs.getInt("cat_id");
            String name = rs.getString("category");
            System.out.println("\tid= " + Int + "\tstr = " + name);
          }//end while loop
    conn.close();
    System.out.println("Disconnected from database");
    catch (Exception e) {
    e.printStackTrace();
    }it works like charm so I don't understand why there are errors once I put rest of the code in.

  • Firefox dose not connect to the internet

    After I installed the firefox 4.0 I can not connect to the internet anymore but I could connect through the explorer from the same cumputer, Itryed eferyyhing wireless or cable.

    Windows 7 has a firewall which controls access to the internet on a program by program basis. It is possible that Firefox is not in the firewall's list of a approved programs.
    Go to the Help feature and search on Firewall and read the information on how to allow a program internet access.
    I don't use the Windows 7 firewall, I use ZoneAlarm's firewall. When I installed ZoneAlarm, I disabled the Windows 7 firewall and have never used. Thus, I can't give you detailed directions as to what you might need to do to allow Firefox to use the internet.
    NOW - are you able to get to the internet with Internet Explorer, just as a test?
    If not, then the problem may be elsewhere, such as your internet connection - dialup, DSL, Cable, etc.
    Stan

  • When I connect my iPhone to my dock it iTunes dose not connect all the time

    I try to connect my iPhone to I tunes but so times it dose see my iPhone. My iphone says that this device is not made for my iPhone. I have 1st gen and I've hade it allmost a year. My friend has a 1st gen and right after the 1year mark passed his started to break down. Now if this happens to me all I got to say is OMG! I've taken my iPhone to the store about 6 months ago and they gave me a new one and vince then I've never droped this one or anything so what's going on!

    Try connecting the phone directly to the USB port on the computer without the dock.

  • Dreamweaver not connecting to mysql?

    I have set up a database in MAMP which Dreamweaver was connected to and all worked fine. I have now copied that database in phpmyadmin via my hosting server and also uploaded all my files to my current (live) site and im now having connection problems, in the database panel in Dreamweaver there is a database present but no tables, when i open the mysql connection dialog box and try to select database or test it, it comes up with - 'unidentified error has occured'
    Does anyone have any idea where i have gone wrong?

    Ness_quick wrote:
    I have set up a database in MAMP which Dreamweaver was connected to and all worked fine. I have now copied that database in phpmyadmin via my hosting server and also uploaded all my files to my current (live) site and im now having connection problems, in the database panel in Dreamweaver there is a database present but no tables, when i open the mysql connection dialog box and try to select database or test it, it comes up with - 'unidentified error has occured'
    Does anyone have any idea where i have gone wrong?
    Humm..Im not sure why you are looking in the Dreamweaver database panel for something on the remote site?
    All you should have needed to do was export the database to a .sql file from your local copy of phpMyAdmin. Open the remote copy of phpMyAdmin and import it.

  • Can't download any apps off my phone, Tablet dos not connect to phone

    Someone please help me, cause I am honestly about to loose my mind. I have a Torch and I've only had it for a year now and all my services arent working, I'm considering switching to an IPhone if I can't figure this all out today.
    So first problem I'm trying to buy one single app off app world billing threw Roger's Canada and it keeps saying there was some error, I looked it up on the website and apperently you just have to switch to debit or paypal, I don't like using online payment methods like that why can't I just get it on my bill? Either way they get the money, I don't see how its so difficult to just bill threw my service provider. I also have no time to call them and tell them all I want to order,  I just want ONE $1.99 app, I'm not going to sit on the phone for 20 minutes+ for one app, then have to do it again when I want another app. I have been trying to buy the same one app for about 2 months now, seriously I just want to buy the app and get it over with how is that so hard? I want to bill threw my Service Provider it takes two seconds to put it on my bill. 
    Next problem, the blackberry bridge on my phone/tablet has just stopped working and disappeared. I paid $500 for this tablet that I was advised not to buy because Blackberry was "going down the whole" so much for having faith in the company, this thing is a peice of junk. And apperently so is my phone, again how is it all the sudden my bridge disappeared? I can't connect my phone to it now? So why didn't I just get a cheaper tablet that could do the exact same things??? I don't know if these are new problems in the system or something but I have been trying to hook up my phone to this tablet for a while it used to work then I upgraded the software and now its gone and I've tried everything its just not coming back. Like I don't understand, why would you not put the Blackberry Bridge in the updated version? And why is it deleted off my phone? Then when I try to re-install it, it says its still there. 
    Very disappionted in Blackberry right now, nothing on my phone is working and it seems I'm not the only one.  

    Hi and Welcome to the Community!
    samm1234 wrote:
    Someone please help me, cause I am honestly about to loose my mind. I have a Torch and I've only had it for a year now and all my services arent working
    Well, I can't tell...has it been working fine for a year, and this suddenly started? If so, what happened just before this behavior started? Undo that to see if it helps. If it's not been working at all for a year, well...I'm not sure how to reply to that...you must have great patience indeed, though.
    samm1234 wrote:
    So first problem I'm trying to buy one single app off app world billing threw Roger's Canada and it keeps saying there was some error, I looked it up on the website and apperently you just have to switch to debit or paypal,
    Oh how I do wish you'd have given us the actual error message...otherwise, you leave us guessing...but, in short, each carrier decides if they will allow carrier billing or not. It's their choice to do so, or not. I've no idea if Rogers allows it or not.
    Also, if you are part of a BES environment, it's possible your BES admins have restricted carrier billing...they, too, have the right to do whatever they must to enforce company policies. But, again, without details, this remains just another guess.
    samm1234 wrote:
    Next problem, the blackberry bridge on my phone/tablet has just stopped working and disappeared. I paid $500 for this tablet that I was advised not to buy because Blackberry was "going down the whole" so much for having faith in the company, this thing is a peice of junk. And apperently so is my phone  
    I completely disagree with your opinions there...but no matter, they are indeed opinions. There are plenty of people who are getting quite a bit of good use out of both types of devices.
    samm1234 wrote:
    again how is it all the sudden my bridge disappeared? I can't connect my phone to it now? 
    Well, once again, the lack of details makes it pretty difficult to diagnose. "I can't connect" is pretty useless as far as symptom descriptions go. For instance, what exact steps do you attempt? What exactly happens with each step? Any error messages? If so, once again, the complete and accurate error message is critical to helping you.
    samm1234 wrote:
    So why didn't I just get a cheaper tablet that could do the exact same things???
    It's a free market place, you are free to do whatever you desire. But, ranting here isn't perhaps the best way to seek help from kind volunteers... Plus, you've spent quite a bit of effort on your rants, but have left out the details that perhaps might have more quickly guided us to useful help for you...
    samm1234 wrote:
    I don't know if these are new problems in the system or something but I have been trying to hook up my phone to this tablet for a while it used to work then I upgraded the software and now its gone and I've tried everything its just not coming back.   
    Again, "tried everything" isn't terribly useful to us...we aren't clairvoyant... Have you tried completely removing the pairing of the two devices and re-configuring them from scratch? Also, what software did you upgrade? Your BB OS? Your PB? From what version(s) to what version(s)? Did you re-install the Bridge from scratch?
    samm1234 wrote:
    Like I don't understand,  
    And, from your lack of details and clarity, neither do we...
    samm1234 wrote:
    why would you not put the Blackberry Bridge in the updated version? 
    Updated version of what? BB Bridge is an add-on app, not used by everyone. As such, including it inside the core apps would be a waste of AppMemory for those who do not need it.
    samm1234 wrote:
    And why is it deleted off my phone?
    Well, you did some kind of upgrade or update, but since we don't know yet exactly what that was, we can only guess. And my guess is that you somehow updated your BB OS, and as such, you need to re-install all of your add-on apps. It is ALWAYS better to reinstall add-on apps when you upgrade the OS...some may not be compatible with the new OS you have installed. Some may have a different version for the OS you installed. Plus, reinstalling add-ons is always better so as to be sure that they are properly installed after such a major update of the BB OS.
    samm1234 wrote:
    Then when I try to re-install it, it says its still there. 
    That's interesting...but, again, the exact message it presents is always more helpful. Check here, though:
    KB10040 How to view or remove installed applications on a BlackBerry smartphone
    Anyway, lots of clarification is needed from you if we're to do anything but WAG.
    Good luck and let us know!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Can not connect to mySql database

    Hi,
    I created a database with tables on my company server.
    I programed a java GUI application to communicate the this database, i.e userlogin.java. Everything works perfectly. However, when I cretate a jnlp for this application, changing the and upload it as well as necessary java jar file to the company web space. Tthe program runs with Java web star but it seems that it get no data from the database. For example, when I type my username and password, it shows that there is no such username in the database which in fact my username exist in the database.
    Thank you.

    Thank you for your answer.
    I'm very new to mySql as server. When I was assigned to write the application, the administrator has set up mySql database in the company web server for my application. My program runs very when using my workplace desktop with java web start or run with java web start in netbeans (all paths should be link to my desktop hard disk, i.e. users/application/). I can not run the application at home because I can not access to the company intranet server (for security purpose). The problem happens when I post the application in the company web page (I have to modify all paths in jnlp file to the company web address). The program then runs without exception except it seems that it gets no data from the database.
    Please help me.
    Thank you in advance.

  • How to fix:  Database connection error (2): Could not connect to MySQL.

    Hi - I am trying to reconnect to a site and continue to get this message.  Can anyone suggest a fix for this?

    That's a server error and has nothing to do with your computer.

  • OSX Server connects to router but dos not reach the internet

    Sorry that i have no answer, but i'd like to add my problem as well.
    I have a OSX Server witch is configured to an Airport Extreme. It is connected to the Router and dos all the sharing on the local network. But same as you describe it dos not connect to the Internet.
    I checked my firewall options and it is set to allow all traffic.
    I can ping the router but i don't get pings from pages on www !?
    If anyone has an Idea where else i might look, i would be grateful for all advice..
    Please drop me a mail on tj{at}daemgen.net
    If anyone has a solution to the problem i will send an coupon for an Starbucks coffee in addition to my appreciation and thanks as i am looking since quite a while by now and it doesn't seem that i see what might cause the problem !!

    There really isn't enough data to answer your question directly, but there are some things to check.
    Being able to ping or serve data to the local network just means that the server has a working network connection, so that's a start, but to get to external sites it needs two things - first, a valid DNS server address that it can use to lookup hostnames, and it needs to know the address of the router on the network that provides an internet connection.
    In this case you should check System Preferences -> Network -> Ethernet -> Advanced and check the TCP/IP settings - make sure the Router (or 'Gateway') address is set to the address of your Airport Extreme. Then check the DNS setting to make sure you have a valid DNS server set.
    If those are correct then you'll need to post back with more data, specifically what you do see/get when you try to access remote sites. What error messages do you get?
    Oh, and while ping might be a good basic test, it isn't absolute - in other words, ping could fail, even when you can connect to a remote server, since pings could be blocked by a firewall or router at either end of the network.

  • My pc do not connect to airport express

    i just got an airport extreme, but my pc (sony vio) dose not connect to internet

    My first suggestion would be to go through the written set up guide that came with the extreme.  In a nutshell:
    Connect the extreme to your modem via an ethernet cable;
    Power up the extreme;
    If it doesn't start on its own, start your Airport Utility (make sure its up to date);
    Go through the steps to set up your wireless network;
    Make sure your PC is connected to the extreme with an ethernet cable or via WI FI.
    Voila!

  • Problem to connect to mysql from servlet using a javabean

    Hi,
    I'm new here and beginner on java to.
    I have problem to connect to MySql database, by a connection javabean.
    It's the following: a HTML page calls a servlet and this servlet imports the package connection javabean.
    It has no problem when I establish the connection inside the servlet, with all its methods (public and private). But i want to separate the code connection from servlet.
    Detail: there is no problem, using the javabean to connect to MS Access database.
    I put "mysql-connector-java-3.1.12-bin.jar" file inside WEB-INF/lib application and common/lib directories.
    I set the classpath:
    SET CLASSPATH=%CATALINA_HOME%\COMMON\LIB\mysql-connector-java-3.1.12-bin.jar;%CLASSPATH%
    I think that the servlet cannot create an instance of javabean, because passed by catch exception of the servlet init method.
    But I don't know why.
    Please Why?
    Below there are the fragment of errors, servlet code e javabean code.
    Thank you.
    Zovao.
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    java.lang.NullPointerException
    at CadServletFileBeanConexArq.doPost(CadServletFileBeanConexArq.java:47)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
    Note: The line 47 is calling insertIntoDB javabean method.
    ========///////////////===============
    // Here is the servlet CadServletFileBeanConexArq.java
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.sql.*;
    import conJdbc.*;
    public class CadServletFileBeanConexArq extends HttpServlet {
    public ConexPed connect = null;
    private String driver = "com.mysql.jdbc.Driver";
    private String URL = "jdbc:mysql://localhost:3306/cadastro";
    public void init( ServletConfig config )
    throws ServletException
    super.init( config );
    try
    connect = new ConexPed(driver, URL, "monty", "some_pass");
    catch ( Exception e )
    e.printStackTrace();
    connect = null;
    public void doPost( HttpServletRequest req,
    HttpServletResponse res )
    throws ServletException
    boolean success = true;
    String email, nome, sobrenome, produto, valor;
    email = req.getParameter( "Email" );
    nome = req.getParameter( "Nome" );
    sobrenome = req.getParameter( "Sobrenome" );
    produto = req.getParameter( "Produto" );
    valor = req.getParameter( "Valor" );
    res.setContentType( "text/html" );
    if ( email.length() > 0 && nome.length() > 0 && sobrenome.length() > 0 && valor.length() > 0 )
    /* inserting data */
    success = connect.insertIntoDB(
    "'" + email + "','" + nome + "','" + sobrenome + "','" + produto + "'", Double.parseDouble(valor) );
    //closing connection
    public void destroy()
    connect.fecharConexao();
    =============///////////////============
    Here is the JavaBean.
    package conJdbc;
    import java.sql.*;
    public class ConexPed
    public Connection connection;
    public Statement statement;
    public ConexPed (String driver, String urlServidor, String user, String password)
    try
    Class.forName(driver);
    connection = DriverManager.getConnection(urlServidor,user,password);
    catch (ClassNotFoundException ex)
    System.out.println("N�o foi poss�vel encontrar a classe do Driver: " + driver);
    catch (SQLException ex)
    System.out.println("N�o foi poss�vel conectar ao servidor");
    try
    statement = connection.createStatement();
    catch (SQLException ex)
    System.out.println("N�o foi poss�vel criar a statement");
    *Inserting data to database
    public synchronized boolean insertIntoDB( String stringtoinsert, double valor)
    try
    statement.executeUpdate( "INSERT INTO pedido values (" + stringtoinsert + " , " + valor + ");" );
    catch ( Exception e ) {
    System.err.println(
    "ERROR: Problemas ao adicionar nova entrada" );
    e.printStackTrace();
    return false;
    return true;
    * Close statement.
    public void fecharStatement()
    try
    statement.close();
    catch (SQLException ex)
    ex.printStackTrace();
    * close database
    public void fecharConexao()
    try
    connection.close();
    catch (SQLException ex)
    ex.printStackTrace();
    }

    Hi,
    I'm new here and beginner on java to.
    I have problem to connect to MySql database, by a connection javabean.
    It's the following: a HTML page calls a servlet and this servlet imports the package connection javabean.
    It has no problem when I establish the connection inside the servlet, with all its methods (public and private). But i want to separate the code connection from servlet.
    Detail: there is no problem, using the javabean to connect to MS Access database.
    I put "mysql-connector-java-3.1.12-bin.jar" file inside WEB-INF/lib application and common/lib directories.
    I set the classpath:
    SET CLASSPATH=%CATALINA_HOME%\COMMON\LIB\mysql-connector-java-3.1.12-bin.jar;%CLASSPATH%
    I think that the servlet cannot create an instance of javabean, because passed by catch exception of the servlet init method.
    But I don't know why.
    Please Why?
    Below there are the fragment of errors, servlet code e javabean code.
    Thank you.
    Zovao.
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    java.lang.NullPointerException
    at CadServletFileBeanConexArq.doPost(CadServletFileBeanConexArq.java:47)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:716)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
    Note: The line 47 is calling insertIntoDB javabean method.
    ========///////////////===============
    // Here is the servlet CadServletFileBeanConexArq.java
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.sql.*;
    import conJdbc.*;
    public class CadServletFileBeanConexArq extends HttpServlet {
    public ConexPed connect = null;
    private String driver = "com.mysql.jdbc.Driver";
    private String URL = "jdbc:mysql://localhost:3306/cadastro";
    public void init( ServletConfig config )
    throws ServletException
    super.init( config );
    try
    connect = new ConexPed(driver, URL, "monty", "some_pass");
    catch ( Exception e )
    e.printStackTrace();
    connect = null;
    public void doPost( HttpServletRequest req,
    HttpServletResponse res )
    throws ServletException
    boolean success = true;
    String email, nome, sobrenome, produto, valor;
    email = req.getParameter( "Email" );
    nome = req.getParameter( "Nome" );
    sobrenome = req.getParameter( "Sobrenome" );
    produto = req.getParameter( "Produto" );
    valor = req.getParameter( "Valor" );
    res.setContentType( "text/html" );
    if ( email.length() > 0 && nome.length() > 0 && sobrenome.length() > 0 && valor.length() > 0 )
    /* inserting data */
    success = connect.insertIntoDB(
    "'" + email + "','" + nome + "','" + sobrenome + "','" + produto + "'", Double.parseDouble(valor) );
    //closing connection
    public void destroy()
    connect.fecharConexao();
    =============///////////////============
    Here is the JavaBean.
    package conJdbc;
    import java.sql.*;
    public class ConexPed
    public Connection connection;
    public Statement statement;
    public ConexPed (String driver, String urlServidor, String user, String password)
    try
    Class.forName(driver);
    connection = DriverManager.getConnection(urlServidor,user,password);
    catch (ClassNotFoundException ex)
    System.out.println("N�o foi poss�vel encontrar a classe do Driver: " + driver);
    catch (SQLException ex)
    System.out.println("N�o foi poss�vel conectar ao servidor");
    try
    statement = connection.createStatement();
    catch (SQLException ex)
    System.out.println("N�o foi poss�vel criar a statement");
    *Inserting data to database
    public synchronized boolean insertIntoDB( String stringtoinsert, double valor)
    try
    statement.executeUpdate( "INSERT INTO pedido values (" + stringtoinsert + " , " + valor + ");" );
    catch ( Exception e ) {
    System.err.println(
    "ERROR: Problemas ao adicionar nova entrada" );
    e.printStackTrace();
    return false;
    return true;
    * Close statement.
    public void fecharStatement()
    try
    statement.close();
    catch (SQLException ex)
    ex.printStackTrace();
    * close database
    public void fecharConexao()
    try
    connection.close();
    catch (SQLException ex)
    ex.printStackTrace();
    }

  • Connecting to MySQL Database with Servlet

    Hi All,
    I want to connect to MySQL Database from servlet.
    I am using Tomcat websever 3.3.1, where i have to set classpath of mysql jdbc driver.
    I tried by copying mysql jdbc driver in so many directiories of Tomcat server but it is
    giving me error like "no specified driver find"
    So please send me all the solutions and how to set the classpath to connect to
    mysql database.
    Thanks

    U r correct that so many people are giving me solutions but that are not working for me
    I think i not correct in setting the classapath to mysql jdbc driver.
    1)I have unjarred correctly and all the classes are present in that.
    yes driver class is there in that .
    2)Now i am using new version of the mysqljdbc that is 2.0.13
    If now any driver after this send me url i will download it and use it
    3)I am unable to under stand what is yourcontext in
    yourcontext/web-inf/lib?
    This is my directory structure.
    c:tomcat in this i have
    bin
    conf
    doc
    lib
    logs
    modules
    native
    webapps
    work
    in bin there are no subdirectories
    in conf i have
    auto,jserv,jk,users
    in doc i have
    appdev,images
    sample( in appdev)
    etc,lib,src,web(in sample)
    images(in sample\web)
    in lib i have
    apps
    common
    container(c:\tomcat\lib)
    in logs,modules there are no subdirectories
    in native (c:\tomcat\native) i have
    mod_jk
    mod_jserv
    in mod_jk i have
    apache 1.3
    common
    iis
    jni
    netscape
    nt_service
    in webapps i have (c:tomcat\webapps)
    Admin,Examples,root
    in Admin i have (c:\tomcat\webapps\admin)
    contextadmin
    Meta-inf
    Test
    Web-inf
    in web-inf (c:\tomcat\webapps\admin\web-inf)
    Classes,lib,script
    in classes i have (c:\tomcat\webapps\admin\web-inf\classes)
    tadm
    in examples (c:\tomcat\webapps\examples) i have
    Images,Jsp,Meta-inf,Servlets,Web-inf
    in web-inf (c:\tomcat\webapps\examples\web-inf) i have
         Classes,jsp
    in classed (c:\tomcat\webapps\examplesweb-inf\classes) i have
    Cal
    Checkbox
    Colors
    Dates
    Error
    Examples
    Num
    Sessions
    in jsp (c:\tomcat\webapps\examples\web-inf\jsp) i have
    applet          
    I think this is enough to give correct answer for me .
    Thanks

  • Connection to MySQL via ODBC not working

    Hello all together,
    I've got a problem with the ODBC connection to MySQL. The connection via ODBC is established and things like tnsping are working.
    When I select some data within the SQL*Plus environment, I get no real result. For example "select table_name from all_tables@mysql;" returns nothing.
    My entry in listener.ora:
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME=odbc_mysql)
    (ORACLE_HOME=D:\oracle\product\11.0.1\db_1)
    (PROGRAM=dg4odbc)
    My entry in tnsnames.ora:
    MYSQL =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA = (SID=odbc_mysql))
    (HS=OK)
    The initodbc_mysql.ora in ORACLE_HOME/hs/admin/:
    HS_FDS_CONNECT_INFO = odbc_mysql
    HS_AUTOREGISTER = TRUE
    HS_DB_NAME = hsodbc
    I tried some modifications but I still get no data from mysql database. When I try "select * from customer@mysql;" I get the correct number of records, the correct column names, but the content is always "¬¬¬¬". The odbc driver works, because with MS Access I can fetch the data. I'm using Oracle 11g Release 1 EE and MySQL ODBC 5.1.5.
    What could be the reason for this?
    Greetings,
    Joerg

    created in my UTF-8 Mysql DB your table and inserted a record; the select shows:
    SQL> select * from "movieclass"@mysql;
    idClass
    ClassName
    123
    H e l l o
    As you can see the content is there, the "space" between the letters is related to unicode. Each character is interpreted by 2 bytes and SQL*Plus wrongly displays both. Using iSQLPLus or SQLDeveloper does not show the "space" between the letters.
    Here the data type mapping:
    SQL> desc "movieclass"@mysql;
    Name Null? Type
    idClass NUMBER(3)
    ClassName NOT NULL NVARCHAR2(50)
    What's the exact version of DG4ODBC you're using? 11.1.0.7?
    According to the listener file you're using DG4ODBC on Windows. There was a high/low byte issue in DG4ODBC for Windows. This issue is fixed in 11.1.0.7 and a certain patch. So I recommend you to get first the 11.1.0.7 patchset (if you don't already have it installed):
    6890831 Oracle Database Family: Patchset
    11.1.0.7.0 PATCH SET FOR ORACLE DATABASE SERVER 11.1.0.7.0
    and then please apply also the latest patch:
    8689191 Oracle Database Family: Patch
    ORACLE 11G 11.1.0.7 PATCH 16 BUG FOR WINDOWS 32 BIT 11.1.0.7.0
    There was a high/low byte issue
    Edited by: kgronau on Aug 11, 2009 10:28 AM

Maybe you are looking for

  • Ipod touch 4G is stuck in "connect to itunes" screen.

    I just got my brand new Ipod Touch 4G (iOS 4.3.5), I connected it to my PC and put some music on it, I was using itunes 10.4. I update to itunes 10.5.0 and it wouldn't recognize my ipod. I searched online for solutions with no luck. Itunes says: "itu

  • ITunes Store connection

    Suddenly I can no longer connect to the iTunes Store. I have accessed the Windows firewall and checked off iTunes. I have downloaded the latest software numerous times and restarted my computer.I still can not connect. Any ideas?

  • Why does my printer not work?

    My HP Printer says it's connected but it does not Print.

  • Re: Where can we buy a new screen for Satellite A200-1k8?

    Hi everyone, I would like to know if it is possible to buy a new screen (all the upper part in fact) for a Satellite A200-1k8 and where ?? I'm unable to find any information about that on the Toshiba website, so may you can help. ;)

  • Any way to have two DVD SP projects open at the same time?

    Hi Since it is likely that I'm going to re-build all the menues in my PAL DVD in a new NTSC project, I'd like to know if there is any way for me to have two separate DVD Studio Pro projects open at the same time. That way I can easily check and copy