You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by pierre madiot <pi...@yahoo.fr> on 2006/07/21 19:25:53 UTC

how to find programatically the max size of a column?

Hello,

I have to design a webapp form which would display an
error message when a <textarea>'s content is beyond
the maximum size of the back-end Derby's table's
column.

The user may at install time choose the size of the
VARCHAR column.

in the context of the MVC i'd like to have the C to
through an error to the V, when it finds out that the
field content sent from the form is larger than the
maximal acceptable from the M.

i'd like to be able to use the jdbc DatabaseMetaData
API to find out the information dynamically. 
I wasn't able to find how how so far.

Ideally, i'd like to find a DB independant way to
retireve this info. I realise this is Derby focus
list, but our deployment targets 2 other major DBs for
now (MySQL and Oracle... would you have guess :).

anyway, thanks for all helps and hints on this.

cheers


	

	
		
___________________________________________________________________________ 
Découvrez un nouveau moyen de poser toutes vos questions quelque soit le sujet ! 
Yahoo! Questions/Réponses pour partager vos connaissances, vos opinions et vos expériences. 
http://fr.answers.yahoo.com 


RE: how to find programatically the max size of a column?

Posted by Michael Segel <ms...@segel.com>.
Not sure exactly what you are asking....

If you want to find out the limits set on the VARCHAR column, the easiest
way to do this is to query the system tables. This is going to be database
dependent.

Since you also want to allow the "end user" to set the limits at install
time, again you are going to be dealing with DDL which is going to be
platform specific. (Note: Most databases use very similar SQL syntax for
their DDL, however there is no guarantee that they will all conform to the
same syntax....)

Having said that...
You should be able to use the java.sql DatabaseMetaData interface, using the
getColumns() method. This should show you the parameters of the existing
VARCHAR column.

Here is the url to the javadoc...
	
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/DatabaseMetaData.html


What makes your request confusing is that this is a derby discussion list,
and you're asking for a generic solution.

If you are writing something primarily for Derby that you would like to keep
as generic as possible for future potential migration efforts, then you will
have to consider what sort of functionality you want to allow. 


HTH,

-G

> -----Original Message-----
> From: pierre madiot [mailto:pitonew@yahoo.fr]
> Sent: Friday, July 21, 2006 12:26 PM
> To: derby-user@db.apache.org
> Subject: how to find programatically the max size of a column?
> 
> Hello,
> 
> I have to design a webapp form which would display an
> error message when a <textarea>'s content is beyond
> the maximum size of the back-end Derby's table's
> column.
> 
> The user may at install time choose the size of the
> VARCHAR column.
> 
> in the context of the MVC i'd like to have the C to
> through an error to the V, when it finds out that the
> field content sent from the form is larger than the
> maximal acceptable from the M.
> 
> i'd like to be able to use the jdbc DatabaseMetaData
> API to find out the information dynamically.
> I wasn't able to find how how so far.
> 
> Ideally, i'd like to find a DB independant way to
> retireve this info. I realise this is Derby focus
> list, but our deployment targets 2 other major DBs for
> now (MySQL and Oracle... would you have guess :).
> 
> anyway, thanks for all helps and hints on this.
> 
> cheers
> 
> 
> 
> 
> 
> 
> __________________________________________________________________________
> _
> Découvrez un nouveau moyen de poser toutes vos questions quelque soit le
> sujet !
> Yahoo! Questions/Réponses pour partager vos connaissances, vos opinions et
> vos expériences.
> http://fr.answers.yahoo.com




Re: how to find programatically the max size of a column?

Posted by Daniel Morton <dj...@yahoo.com>.
If you run the getColumns(...) method of a
DatabaseMetaData object, you get a result set with all
the columns in the specified table.  The 7th field in
the each row of the result set is the max number of
characters allowed if the corresponding column is a
text field.  

For more info, look at:

http://java.sun.com/j2se/1.5.0/docs/api/java/sql/DatabaseMetaData.html#getColumns(java.lang.String,
java.lang.String, java.lang.String, java.lang.String)


Dan Morton


--- pierre madiot <pi...@yahoo.fr> wrote:

> Hello,
> 
> I have to design a webapp form which would display
> an
> error message when a <textarea>'s content is beyond
> the maximum size of the back-end Derby's table's
> column.
> 
> The user may at install time choose the size of the
> VARCHAR column.
> 
> in the context of the MVC i'd like to have the C to
> through an error to the V, when it finds out that
> the
> field content sent from the form is larger than the
> maximal acceptable from the M.
> 
> i'd like to be able to use the jdbc DatabaseMetaData
> API to find out the information dynamically. 
> I wasn't able to find how how so far.
> 
> Ideally, i'd like to find a DB independant way to
> retireve this info. I realise this is Derby focus
> list, but our deployment targets 2 other major DBs
> for
> now (MySQL and Oracle... would you have guess :).
> 
> anyway, thanks for all helps and hints on this.
> 
> cheers
> 
> 
> 	
> 
> 	
> 		
>
___________________________________________________________________________
> 
> Découvrez un nouveau moyen de poser toutes vos
> questions quelque soit le sujet ! 
> Yahoo! Questions/Réponses pour partager vos
> connaissances, vos opinions et vos expériences. 
> http://fr.answers.yahoo.com 
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com