Results 1 to 10 of 10
Thread: Servlets and database problem
- 11-20-2012, 07:42 PM #1
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
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); } }
- 11-20-2012, 09:42 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Re: Servlets and database problem
Is the mysql driver on the classpath of the servlet container? Based upon the exception the answer is no.No suitable driver found for jdbc:mysql
- 11-20-2012, 10:39 PM #3
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
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?
- 11-20-2012, 11:03 PM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Re: Servlets and database problem
- 11-21-2012, 12:38 AM #5
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
Re: Servlets and database problem
I have been looking over the documentation, can't find anything that has helped so far
- 11-21-2012, 02:35 AM #6
Member
- Join Date
- Apr 2009
- Posts
- 11
- Rep Power
- 0
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.
- 11-21-2012, 03:45 AM #7
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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.Website: Learn Java by Examples
- 11-21-2012, 05:58 AM #8
Member
- Join Date
- Nov 2012
- Posts
- 2
- Rep Power
- 0
Re: Servlets and database problem
please refer to mysql documentation link MySQL :: MySQL 5.1 Reference Manual :: 21.3.6 JDBC Concepts
- 11-21-2012, 06:49 AM #9
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
- 11-21-2012, 03:08 PM #10
Senior Member
- Join Date
- Aug 2011
- Posts
- 116
- Rep Power
- 0
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
-
How to create xml file using servlets from database data?
By kkji in forum Advanced JavaReplies: 7Last Post: 08-24-2011, 07:23 PM -
insert data to PostgreSQL database using Jsp and Servlets
By athi in forum JDBCReplies: 2Last Post: 03-29-2011, 12:08 PM -
how to load values from database on pageload using servlets
By kirankumar1231 in forum Java ServletReplies: 3Last Post: 01-26-2011, 08:48 AM -
how to access derby database with servlets
By Mateen in forum Java ServletReplies: 0Last Post: 07-12-2010, 09:16 PM -
problem compiling servlets
By boy22 in forum Java ServletReplies: 1Last Post: 08-03-2007, 10:05 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks