• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

JDBC in JSP not working

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 40747
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed variables.
In the console i get this:

Any ideas?
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic