Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC in JSP not working

 
Popescu Ion
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34401
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Popescu Ion
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed variables.
In the console i get this:

Any ideas?
 
Lingan Rajan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic