• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simple question about using JDBC to access DB2

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,


I want to use JDBC to access DB2 database. I also want to display the content of a specific table (table name is configurable) into web page (just like what is displayed when we use command line "select * from <table name>" on the console). I am wondering whether there are any existing sample which is easy and quick to learn with source codes.


thanks in advance,
George
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"GeorgeNew GeorgeNew,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name. You can edit your name here.

We have a forum specifically for JDBC. You will probably get better responses there, so I'll move this post for you...

-Marc
[ February 22, 2006: Message edited by: marc weber ]
 
George Lin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
marc,


Originally posted by marc weber:
"GeorgeNew GeorgeNew,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name. You can edit your name here.

We have a forum specifically for JDBC. You will probably get better responses there, so I'll move this post for you...

-Marc

[ February 22, 2006: Message edited by: marc weber ]



I have just changed my name. Thank you very much for your thread moving. Cool.


regards,
George
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by GeorgeNew GeorgeNew:
I want to use JDBC to access DB2 database. I also want to display the content of a specific table (table name is configurable) into web page (just like what is displayed when we use command line "select * from <table name>" on the console).



Normally, Java folk who want to dynamicly generate web pages do so using JSP (Java Server Pages), which is a J2EE technology. A lot of people are using Tomcat and/or JBOSS as their J2EE engine, but there are a lot of other choices.

As far as getting started with JDBC, and with JDBC and JSP, here are some good links:
http://java.sun.com/docs/books/tutorial/jdbc/index.html
http://www.javaolympus.com/J2SE/Database/JDBC/JDBCJSP.jsp
 
George Lin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
stu,


Originally posted by stu derby:


Normally, Java folk who want to dynamicly generate web pages do so using JSP (Java Server Pages), which is a J2EE technology. A lot of people are using Tomcat and/or JBOSS as their J2EE engine, but there are a lot of other choices.

As far as getting started with JDBC, and with JDBC and JSP, here are some good links:
http://java.sun.com/docs/books/tutorial/jdbc/index.html
http://www.javaolympus.com/J2SE/Database/JDBC/JDBCJSP.jsp




Thank you very much! The links are very helpful. The questions I had is how to make UI on web pages to present data retrieved from database. I do not want to make this work too complex like J2EE since my requirements are very simple -- just display the content of a whole table by the table name.

Do you have any further comments?


regards,
George
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"George George",

Your display name must be a first and last name -- not your first name twice. Please adjust your display name to be a first and last name prior to your next post.

Be advised that accounts with invalid display names are subject to removal.

bear
JavaRanch Sheriff
 
George Lin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,


Originally posted by Bear Bibeault:
"George George",

Your display name must be a first and last name -- not your first name twice. Please adjust your display name to be a first and last name prior to your next post.

Be advised that accounts with invalid display names are subject to removal.

bear
JavaRanch Sheriff



I have changed my display name. Please review. Please also feel free to let me know if I need to do further updates. :-)


thanks a lot,
George
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It may seem simple to you, but it's not. The part you're not thinking about is the network part; the code that opens a socket, listens for a web request, dispatches any requests for processing and simultaneously keeps listening for more requests, deals with sockets that are abruptly closed (because the browser was stopped, etc., etc.

While you may not need a full-blown J2EE server, you do need to either write all the above and more, or use a servlet container. Tomcat is the most popular, and free.
http://tomcat.apache.org/

Once you have a servlet container running, then you can start thinking about how to populate the content of your web pages.
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stu is right, George. There is no way to catch the bus without getting to the bus stop.
Suppose you have had tomcat installed and running first.
Write your jsp page or servlet class using jdbc to connect to your db
In your JSP page/Servlet class, parse the ResultSet(You may want to use ResultSet MetaData's getColumnName() method to get the table names)
Use a HTML Table to display your table content -- the column names being the table headers.
(And close your connection)
I have some examples of my own and if you're interested, let me know offline, I'd be happy to share with u.
 
reply
    Bookmark Topic Watch Topic
  • New Topic