aspose file tools*
The moose likes JDBC and the fly likes Get Column Value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Get Column Value" Watch "Get Column Value" New topic
Author

Get Column Value

Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
Hi,

Does anybody know of a sql statement that will get the default value for a field?? eg: Varchar 20.

I have searched the web and have only been able to find SELECT LEN(colName) FROM tableName
and SELECT DATALENGTH(colName) FROM tableName

but these return the entered value(data actually in the table) eg 6 or in bytes eg 9 Is there any way to get the default value?

Thanks


Potrzeba jest matka wynalazków
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Maja Gralewska wrote:
Does anybody know of a sql statement that will get the default value for a field?? eg: Varchar 20.


I think this will help, This method will give you information about table, its column, its data type, default value, etc...


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
Thanks, it's very very useful, defiantly going to bookmark it, but the my problem is its getting the values through java methods, but i preferably have to get it using a mySql statement?(almost the whole system is based like that) Any ideas??? Thanks
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Maja Gralewska wrote: but i preferably have to get it using a mySql statement?(almost the whole system is based like that) Any ideas??? Thanks

I don't thinks that make any difference, JDBC drivers are vendor specific, so what are you doing using 'DatabaseMetadata' interface, internally it invokes the right procedure/select statement to fetch schema information..

Still you want a MySQL specific query, Have look at this blog entry OR better Googled mysql + get schema information it !!
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
Thanks,

I have been looking through the web including the official sun mySql page, and this is most probably my fault for not phasing my question perfectly.(sorry) I can get the type eg: VARCHAR 20 and the data eg: MONKEY and the size of monkey eg: 6, but what i am trying to get using a mySql statement is the 20. eg if in the table its set as VARCHAR 55 then i want to get only the 55 not the whole type, just the set size.

Any ideas?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Maja Gralewska wrote:Thanks,

if in the table its set as VARCHAR 55 then i want to get only the 55 not the whole type, just the set size.


The link I posted in my previous reply has the query to get the table information, specifically the query goes like this,



and it return a row, having following column,

Field, Type(varchar(50)), Null(YES/NO), Key, Default, Extra

Hope this help !!

And whats this means
"Potrzeba jest matka wynalazków " (your signature)
Maja Gralewska
Ranch Hand

Joined: Sep 26, 2008
Posts: 92
Yes thanks it did, although still need to play around with it so it returns only the value/size of char/varchar.

It means: Necessity is the mother of invention.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get Column Value
 
Similar Threads
how to get last inserted row in MySql through JSP
Converting LONGVARBINARY of HSQL to BLOB of Derby
JApplet not connecting to SQL database
How to use Bind Variable in my java program
Number of rows in a table?