| Author |
JDBC in JSP not working
|
Popescu Ion
Ranch Hand
Joined: Jan 14, 2011
Posts: 33
|
|
Hi all,
In Eclipse a choosed new -> Dynamic Web Project. Then I selected tomcat (as runtime) and jdk. Next, created a jsp file, named index.
I want, to connect to MySQL, and retrieve the data. I have already created a table named "catalog" under a database named "catalog" and filled it with data. Table columns are id(int), name (varchar), location (varchar) and marker(boolean). When are run it , i get on the browser screen only "Test!". Why it doesn't print "Int01" value ?
I'll appreciate any help. Thnx in advance.
P.S: Sorry for my english.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
Popescu,
Some best practices:
1) It is better not to have Java code, especially JDBC, in a JSP. It is harder to read/debug/maintain. JSPs are meant for display logic. Search for MVC to see what you should to instead.
2) The result set/statement/connection should be closed in a finally block in case there is a database error.
3) Variable names being with lowercase in Java so "Int01" should be "int01". Or better still "id" so someone reading the code knows what it is.
On your actual question, is there an error message in the system error logs? There should be if the code is throwing an exception.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Popescu Ion
Ranch Hand
Joined: Jan 14, 2011
Posts: 33
|
|
I changed variables.
In the console i get this:
Any ideas?
|
 |
Lingan Rajan
Ranch Hand
Joined: Jan 26, 2011
Posts: 30
|
|
Popescu Ion
The jdbc driver for mysql - com.mysql.jdbc.Driver is not been found in runtime.
You will have to add the jar to the WAR .
|
 |
Popescu Ion
Ranch Hand
Joined: Jan 14, 2011
Posts: 33
|
|
Lingan Rajan wrote:Popescu Ion
The jdbc driver for mysql - com.mysql.jdbc.Driver is not been found in runtime.
You will have to add the jar to the WAR .
Thnx, it works now.
|
 |
 |
|
|
subject: JDBC in JSP not working
|
|
|