Results 1 to 10 of 10
  1. #1
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default Servlets and database problem

    I have a servlet which performs some operations on a database i have already set up and had working.
    I am only performing simple tasks so that i can add, remove and display the data. I have set up a small tester program to test my database methods separate form my servlet. This works fine and i can add, delete and display the data. When i use my servlet below, the browser redirects to a blank page and the console output says
    INFO: SQLExceptionjava.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/university

    I dont understand why i am getting a no suitable driver found message, when i am using the same connection method in my test program . . . the only difference is i am calling the method in the servlet below.

    Java Code:
    StudentOperations operation;
        public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
        {
            try
            {
                operation = new StudentOperations();
                String delete = request.getParameter("delete");
                System.out.println(""+delete);
                operation.removeStudent(delete);
            } catch(ClassNotFoundException e) {
                System.out.println("ClassNotFoundException" + e);
            } catch(SQLException e) {
                System.out.println("SQLException" + e);
            }
            
        }

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Servlets and database problem

    No suitable driver found for jdbc:mysql
    Is the mysql driver on the classpath of the servlet container? Based upon the exception the answer is no.

  3. #3
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default Re: Servlets and database problem

    I have set the classpath to the jar by right clicking on my libaries folder and linking to the .jar file.
    Would i have to separately do this for the servlet files? how could i do this in netbeans?

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Servlets and database problem

    Quote Originally Posted by wdh321 View Post
    I have set the classpath to the jar by right clicking on my libaries folder and linking to the .jar file.
    Would i have to separately do this for the servlet files? how could i do this in netbeans?
    You need to consult the documentation of the servlet container (server) you are using for information on how to add libraries to the classpath. I do not use netbeans, I may be mistaken but doubt adding the jar to your project will deploy it the server.

  5. #5
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default Re: Servlets and database problem

    I have been looking over the documentation, can't find anything that has helped so far

  6. #6
    VanGo is offline Member
    Join Date
    Apr 2009
    Posts
    12
    Rep Power
    0

    Default Re: Servlets and database problem

    I am so new to Java it is not likely I will be of much help.
    But I have been using Netbeans to connect to a mySQL database

    On a windows machine I had to go to the "Control Panel" then to "Administrative Tools" then to "Data Sources ODBC" then to "System DNS" and here I had to Add the connection to my data base.
    Sorry if this is just obvious stuff and you already know. Not doing it gave me the same error your getting.
    Good luck.

  7. #7
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Servlets and database problem

    For web application you can simply put all the libraries used by your web application under the WEB-INF/lib directory. So please put your MySQL Connector 4 Java in that directory so that your Servlet can load the JDBC driver.

    For your other classes it should go the the WEB-INF/classes directory.

  8. #8
    gvnreddy145 is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default Re: Servlets and database problem

    please refer to mysql documentation link MySQL :: MySQL 5.1 Reference Manual :: 21.3.6 JDBC Concepts

  9. #9
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Servlets and database problem

    Quote Originally Posted by wdh321 View Post
    I have been looking over the documentation, can't find anything that has helped so far
    You have not provided any information regarding the server you are using, without which it leaves people guessing.

  10. #10
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default Re: Servlets and database problem

    Sorry i thought i had said, i am using glassfish. After reading through a lot of documentation i found a number of different locations the .jar file can be placed. These included the WEB-INF/lib folder, domain1/lib and also domain1/lib/applibs. To save time incase these didn't work i put the jar in all 3 locations and it seems to be working! I am sure i have tried using the jar file in these three locations separately before but it did not work. I will try and see which location it is getting used from now.

Similar Threads

  1. Replies: 7
    Last Post: 08-24-2011, 07:23 PM
  2. Replies: 2
    Last Post: 03-29-2011, 12:08 PM
  3. how to load values from database on pageload using servlets
    By kirankumar1231 in forum Java Servlet
    Replies: 3
    Last Post: 01-26-2011, 08:48 AM
  4. how to access derby database with servlets
    By Mateen in forum Java Servlet
    Replies: 0
    Last Post: 07-12-2010, 09:16 PM
  5. problem compiling servlets
    By boy22 in forum Java Servlet
    Replies: 1
    Last Post: 08-03-2007, 10:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •