This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of DevSecOps Adventures: A Game-Changing Approach with Chocolate, LEGO, and Coaching Games and have Dana Pylayeva on-line!
See this thread for details.
  • 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
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

describing the table!!!...

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friend,
Upto some extend i know jdbc. how to describe a table in jdbc and getting info(fieldname and datatype) about the table?
Thank u.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the database Metadata interface for database info and the resultset metadata interface for table related info.
 
bala chidambaram
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank u bello...
create table student
(
name varchar2(20),
rno number(2)
};
would u help me with this example?
Thank u.
 
author & internet detective
Posts: 41988
911
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
Bala,
You would do a "select * from student" query to get a resultset. Then you would use the rs.getMetaData() method to navigate through the metadata referenced above.
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a couple of ways of doing this. One is to use the DatabaseMetaData and the other is to use the ResultSetMetaData. Both methods require a database connection, but the first method doesn't require you to run a query.
To use the DatabaseMetaData, here's an example (for Oracle):

The statement "rs = dbmd.getTables(null, "some-user", "%", xxx);" looks for
all tables in the "some-user" schema. If you want tables regardless of the schema, replace "some-user" with null. If you want to look at a specific table, put that table name in place of the "%" (the wildcard specification).
There is a lot of useful database information that can be pulled from the DatabaseMetaData.
If you go the second route as Jeanne has pointed out, I'd use the following query instead:
"select * from student where 1 = 2"
Since student (or any other table) might contain a large number of rows, there is no need to force the database to do a lot of work. If you give it an invalide condition it won't return any rows, but you'll still get the ResultSetMetaData, and can query for the column names and types.
I've tested the above approach using Oracle, Sybase and MySql and it works with each of these.
If you had a key field, such as "int studentId", you could use:
"select * from student where studentId = 0" and it would have the same affect.
 
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic