Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Why JDBC cannot be used to select column types for all SQL server

Reply
Thread Tools

Why JDBC cannot be used to select column types for all SQL server

 
 
Sigfried
Guest
Posts: n/a
 
      09-05-2008
I've spent 2 days to find out that the JDBC MetaData getTypeInfo() is
not enough to choose:
1/ which java.sql.Types.XXX : to use
2/ which corresponding column type to choose (in create table sql)

I ended up testing the url string, for each vendor i tested (assuming
the last version for the server), having hard coded values.
 
Reply With Quote
 
 
 
 
Msj121
Guest
Posts: n/a
 
      09-05-2008
On Sep 5, 2:02 am, Sigfried <sig.fr...@hotmail.com> wrote:
> I've spent 2 days to find out that the JDBC MetaData getTypeInfo() is
> not enough to choose:
> 1/ which java.sql.Types.XXX : to use
> 2/ which corresponding column type to choose (in create table sql)
>
> I ended up testing the url string, for each vendor i tested (assuming
> the last version for the server), having hard coded values.


The question seems difficult to understand. In regard to "types" is
this because you want to be able to read in data from any table using
one class and do this dynamically? So one class to read any table and
put it into any object? Though I would suggest using JEE 5 (or
Hibernate) you could scrounge together a simple solution of looking at
the object your making and assume the columns match the data type (if
not then there is a mistake in object code or database). I could only
suggest this for a small project though where you have a handle on
everything. I think Hibernate or JEE 5 EJBs would be better.

Also, when creating SQL tables - what do you mean you don't know the
corresponding column type. Does this mean based on the object you
don't know how to dynamically create a table for that object type? I
still suggest EJBs and Hibernate for this, but a translator used in
the original idea could be implemented here as well. It shouldn't be
overly complicated as there aren't that many object types.

Perhaps I misunderstood the problem.

MSJ121
 
Reply With Quote
 
 
 
 
Sigfried
Guest
Posts: n/a
 
      09-05-2008
Msj121 a écrit :
> On Sep 5, 2:02 am, Sigfried <sig.fr...@hotmail.com> wrote:
>> I've spent 2 days to find out that the JDBC MetaData getTypeInfo() is
>> not enough to choose:
>> 1/ which java.sql.Types.XXX : to use
>> 2/ which corresponding column type to choose (in create table sql)
>>
>> I ended up testing the url string, for each vendor i tested (assuming
>> the last version for the server), having hard coded values.

>
> The question seems difficult to understand. In regard to "types" is
> this because you want to be able to read in data from any table using
> one class and do this dynamically? So one class to read any table and
> put it into any object? Though I would suggest using JEE 5 (or
> Hibernate) you could scrounge together a simple solution of looking at
> the object your making and assume the columns match the data type (if
> not then there is a mistake in object code or database). I could only
> suggest this for a small project though where you have a handle on
> everything. I think Hibernate or JEE 5 EJBs would be better.
>
> Also, when creating SQL tables - what do you mean you don't know the
> corresponding column type. Does this mean based on the object you
> don't know how to dynamically create a table for that object type? I
> still suggest EJBs and Hibernate for this, but a translator used in
> the original idea could be implemented here as well. It shouldn't be
> overly complicated as there aren't that many object types.
>
> Perhaps I misunderstood the problem.


Without using heavy tools like Hibernate, i wanted to export some data
to "any SQL server". So if i have text data of fixed size, using only
JDBC, i should use java.sql.DatabaseMetaData.getTypeInfo(), and keep the
first typename corresponding to java.sql.Types.VARCHAR. Then i will do:

create table (
....
columnName typename(maxSize),
....
)

But the same code didn't work for mysql and postgresql.

I would need this method in jdbc:

/**
* @param maxSize if > 0, strings will be of maximum length maxSize
*/
getLimitedTextColumnDataType(int maxSize);

This method would return "varchar(200)" without having to read the SQL
server documentation... What is called a generic way i assume.

And i won't talk about charset encoding...

 
Reply With Quote
 
Msj121
Guest
Posts: n/a
 
      09-05-2008
On Sep 5, 3:13 am, Sigfried <sig.fr...@hotmail.com> wrote:
> Msj121 a écrit :
>
>
>
> > On Sep 5, 2:02 am, Sigfried <sig.fr...@hotmail.com> wrote:
> >> I've spent 2 days to find out that the JDBC MetaData getTypeInfo() is
> >> not enough to choose:
> >> 1/ which java.sql.Types.XXX : to use
> >> 2/ which corresponding column type to choose (in create table sql)

>
> >> I ended up testing the url string, for each vendor i tested (assuming
> >> the last version for the server), having hard coded values.

>
> > The question seems difficult to understand. In regard to "types" is
> > this because you want to be able to read in data from any table using
> > one class and do this dynamically? So one class to read any table and
> > put it into any object? Though I would suggest using JEE 5 (or
> > Hibernate) you could scrounge together a simple solution of looking at
> > the object your making and assume the columns match the data type (if
> > not then there is a mistake in object code or database). I could only
> > suggest this for a small project though where you have a handle on
> > everything. I think Hibernate or JEE 5 EJBs would be better.

>
> > Also, when creating SQL tables - what do you mean you don't know the
> > corresponding column type. Does this mean based on the object you
> > don't know how to dynamically create a table for that object type? I
> > still suggest EJBs and Hibernate for this, but a translator used in
> > the original idea could be implemented here as well. It shouldn't be
> > overly complicated as there aren't that many object types.

>
> > Perhaps I misunderstood the problem.

>
> Without using heavy tools like Hibernate, i wanted to export some data
> to "any SQL server". So if i have text data of fixed size, using only
> JDBC, i should use java.sql.DatabaseMetaData.getTypeInfo(), and keep the
> first typename corresponding to java.sql.Types.VARCHAR. Then i will do:
>
> create table (
> ...
> columnName typename(maxSize),
> ...
> )
>
> But the same code didn't work for mysql and postgresql.
>
> I would need this method in jdbc:
>
> /**
> * @param maxSize if > 0, strings will be of maximum length maxSize
> */
> getLimitedTextColumnDataType(int maxSize);
>
> This method would return "varchar(200)" without having to read the SQL
> server documentation... What is called a generic way i assume.
>
> And i won't talk about charset encoding...


I think I have a better idea as to what you mean now. I have never
attempted to do that kind of thing from scratch (except where I knew a
few different databases would be used and extended based off of them),
but I have seen Hibernate with some different XML connection types
allowing interfacing with the same code to different databases... but
you did say you didn't want Hibernate.

Certainly an interesting idea, but I don't think it will be an easy
solution without using some framework like Hibernate.

 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      09-05-2008
Sigfried wrote:
> Without using heavy tools like Hibernate, i wanted to export some data
> to "any SQL server". So if i have text data of fixed size, using only
> JDBC, i should use java.sql.DatabaseMetaData.getTypeInfo(), and keep the
> first typename corresponding to java.sql.Types.VARCHAR. Then i will do:
>
> create table (
> ...
> columnName typename(maxSize),
> ...
> )
>
> But the same code didn't work for mysql and postgresql.
>
> I would need this method in jdbc:
>
> /**
> * @param maxSize if > 0, strings will be of maximum length maxSize
> */
> getLimitedTextColumnDataType(int maxSize);
>
> This method would return "varchar(200)" without having to read the SQL
> server documentation... What is called a generic way i assume.


But getTypeInfo also return the max length of the type, so you can
loathsomely optimize getLimitedTextColumnDataType yourself.

Jay


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Freemasonry has a religious service to commit the body of a deceased
brother to the dust whence it came, and to speed the liberated spirit
back to the Great Source of Light. Many Freemasons make this flight
with *no other guarantee of a safe landing than their belief in the
religion of Freemasonry*"

 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      09-06-2008
Sigfried wrote:
> Without using heavy tools like Hibernate, i wanted to export some data
> to "any SQL server". So if i have text data of fixed size, using only
> JDBC, i should use java.sql.DatabaseMetaData.getTypeInfo(), and keep the
> first typename corresponding to java.sql.Types.VARCHAR. Then i will do:
>
> create table (
> ...
> columnName typename(maxSize),
> ...
> )
>
> But the same code didn't work for mysql and postgresql.
>
> I would need this method in jdbc:
>
> /**
> * @param maxSize if > 0, strings will be of maximum length maxSize
> */
> getLimitedTextColumnDataType(int maxSize);
>
> This method would return "varchar(200)" without having to read the SQL
> server documentation... What is called a generic way i assume.


But getTypeInfo also return the max length of the type, so you can
easily implement getLimitedTextColumnDataType yourself.

Arne
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      09-08-2008
Sigfried wrote:
> [Quelqu'un qui n'est pas] Arne Vajh??j a ??crit :
>> But getTypeInfo also return the max length of the type, so you can
>> loathsomely optimize getLimitedTextColumnDataType yourself.


Please do not quote the swindler. Quote what Nicole consciously did write.

What he certainly wrote:
> But getTypeInfo also return the max length of the type, so you can
> easily implement getLimitedTextColumnDataType yourself.


--
Lew



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Here in the United States, the Zionists and their co-religionists
have complete control of our government.

For many reasons, too many and too complex to go into here at this
time, the Zionists and their co-religionists rule these
United States as though they were the absolute monarchs
of this country.

Now you may say that is a very broad statement,
but let me show you what happened while we were all asleep..."

--- Benjamin H. Freedman

[Benjamin H. Freedman was one of the most intriguing and amazing
individuals of the 20th century. Born in 1890, he was a successful
Jewish businessman of New York City at one time principal owner
of the Woodbury Soap Company. He broke with organized Jewry
after the Judeo-Communist victory of 1945, and spent the
remainder of his life and the great preponderance of his
considerable fortune, at least 2.5 million dollars, exposing the
Jewish tyranny which has enveloped the United States.]

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      09-08-2008
Sigfried wrote:
> [Quelqu'un qui n'est pas] Arne Vajh??j a ??crit :
>> But getTypeInfo also return the max length of the type, so you can
>> loathsomely optimize getLimitedTextColumnDataType yourself.


Please do not quote the swindler. Quote what Nicole consciously did write.

What he certainly wrote:
> But getTypeInfo also return the max length of the type, so you can
> easily implement getLimitedTextColumnDataType yourself.


--
Lew



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Here in the United States, the Zionists and their co-religionists
have complete control of our government.

For many reasons, too many and too complex to go into here at this
time, the Zionists and their co-religionists rule these
United States as though they were the absolute monarchs
of this country.

Now you may say that is a very broad statement,
but let me show you what happened while we were all asleep..."

--- Benjamin H. Freedman

[Benjamin H. Freedman was one of the most intriguing and amazing
individuals of the 20th century. Born in 1890, he was a successful
Jewish businessman of New York City at one time principal owner
of the Woodbury Soap Company. He broke with organized Jewry
after the Judeo-Communist victory of 1945, and spent the
remainder of his life and the great preponderance of his
considerable fortune, at least 2.5 million dollars, exposing the
Jewish tyranny which has enveloped the United States.]

 
Reply With Quote
 
Sigfried
Guest
Posts: n/a
 
      09-08-2008
Arne Vajhøj a écrit :
> Sigfried wrote:
>> Without using heavy tools like Hibernate, i wanted to export some data
>> to "any SQL server". So if i have text data of fixed size, using only
>> JDBC, i should use java.sql.DatabaseMetaData.getTypeInfo(), and keep the
>> first typename corresponding to java.sql.Types.VARCHAR. Then i will do:
>>
>> create table (
>> ...
>> columnName typename(maxSize),
>> ...
>> )
>>
>> But the same code didn't work for mysql and postgresql.
>>
>> I would need this method in jdbc:
>>
>> /**
>> * @param maxSize if > 0, strings will be of maximum length maxSize
>> */
>> getLimitedTextColumnDataType(int maxSize);
>>
>> This method would return "varchar(200)" without having to read the SQL
>> server documentation... What is called a generic way i assume.

>
> But getTypeInfo also return the max length of the type, so you can
> loathsomely optimize getLimitedTextColumnDataType yourself.


The max length ? Where ? I only saw "create param" and it's more a
grammar description like [(M|A)] for example. Anyway, postgresql returns
null for this field.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Oracle jdbc sql select for update in python loial Python 0 11-17-2010 03:41 PM
Re: java.sql.Date value truncated using JDBC in MS-SQL Server Lew Java 0 02-09-2007 01:21 AM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver Keith Wansbrough Java 0 08-16-2004 07:31 PM
implement "select all" button to select all checkboxes Matt ASP General 2 01-11-2004 01:08 PM



Advertisments