Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Interfaces Jdbc > JDBC types vs p...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 1950 of 1997
Post > Topic >>

JDBC types vs postgres types correspondation

by solinas.marco@[EMAIL PROTECTED] ("Marco Solinas") May 10, 2008 at 07:14 PM

------=_Part_13976_20167192.1210439655817
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Dear list,

We have a problem with the JDBC types. We need to find out the
correspondation table between jdbc types and postgresql type.
What we're trying to do is to build a CREATE TABLE query where a column
has
to be of type "character varying", but we're not able to find the
corresponding JDBC type.
Here you have the related part of out Java code:

*******************************************************************************************************************
    public String getTargetType (int jdbctype) throws SQLException {
        targettype.beforeFirst(); // targettype is the ResultSet obtained
by
DatabaseMetaData
        while (targettype.next()) {
            if (targettype.getInt ("DATA_TYPE") == jdbctype) {
                return targettype.getString("TYPE_NAME");
            }
        }
        return null;
    }

    public void creaTabellaCommesse () {
        String sql = "CREATE TABLE Commesse (";

        try {
            String dbChar = getTargetType(Types.VARCHAR);
            sql += "ID_Commessa " + getTargetType(Types.INTEGER) + "
PRIMARY
KEY, ";
            sql += "Prodotto " + dbChar + ", ";
            sql += "Finitura " + dbChar + ", ";
            sql += "DenominazioneUso " + dbChar + ", ";
            sql += "DestinazioneUso " + dbChar + ", ";
            sql += "PaeseDiDestinazione " + dbChar + ")";

            int n = st.executeUpdate(sql); //the Statement st is allocated
elsewhere of my code
        }
        catch (SQLException ex) {
            eccezione (ex);
        }
    }
****************************************************************************************************************

The jdbc driver we downloaded is postgresql-8.3-603.jdbc4.jar; the
postgresql server version we installed is 8.3.
Our code doesn't provide me any error, but the table columns are of type
"name", which is too short in length to be effective in storing the most
part of our program string.
Any idea of what we're missing?

Thanks a lot for your sup****t.
Regards,
Marco and Rita.

------=_Part_13976_20167192.1210439655817
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Dear list,<br><br>We have a problem with the JDBC types. We need to find
out the correspondation table between jdbc types and postgresql
type.<br>What we&#39;re trying to do is to build a CREATE TABLE query
where a column has to be of type &quot;character varying&quot;, but
we&#39;re not able to find the corresponding JDBC type.<br>
Here you have the related part of out Java
code:<br><br>*******************************************************************************************************************<br>&nbsp;&nbsp;&nbsp;
public String getTargetType (int jdbctype) throws SQLException {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; targettype.beforeFirst(); //
targettype is the ResultSet obtained by
DatabaseMetaData<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while
(targettype.next()) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; if (targettype.getInt (&quot;DATA_TYPE&quot;) ==
jdbctype) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; return targettype.getString(&quot;TYPE_NAME&quot;);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
}<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; return null;<br>&nbsp;&nbsp;&nbsp;
}<br><br>&nbsp;&nbsp;&nbsp; public void creaTabellaCommesse ()
{<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String sql = &quot;CREATE TABLE
Commesse (&quot;;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String dbChar =
getTargetType(Types.VARCHAR);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sql +=
&quot;ID_Commessa &quot; + getTargetType(Types.INTEGER) + &quot; PRIMARY
KEY, &quot;;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
sql += &quot;Prodotto &quot; + dbChar + &quot;,
&quot;;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sql +=
&quot;Finitura &quot; + dbChar + &quot;, &quot;;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sql +=
&quot;DenominazioneUso &quot; + dbChar + &quot;,
&quot;;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sql +=
&quot;DestinazioneUso &quot; + dbChar + &quot;,
&quot;;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sql +=
&quot;PaeseDiDestinazione &quot; + dbChar + &quot;)&quot;;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int n =
st.executeUpdate(sql); //the Statement st is allocated elsewhere of my
code<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; catch (SQLException ex) {<br>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; eccezione
(ex);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;
}<br>****************************************************************************************************************<br>
<br>The jdbc driver we downloaded is postgresql-8.3-603.jdbc4.jar; the
postgresql server version we installed is 8.3.<br>Our code doesn&#39;t
provide me any error, but the table columns are of type &quot;name&quot;,
which is too short in length to be effective in storing the most part of
our program string.<br>
Any idea of what we&#39;re missing?<br><br>Thanks a lot for your
sup****t.<br>Regards,<br>Marco and Rita.<br>

------=_Part_13976_20167192.1210439655817--
 




 2 Posts in Topic:
JDBC types vs postgres types correspondation
solinas.marco@[EMAIL PROT  2008-05-10 19:14:13 
Re: JDBC types vs postgres types correspondation
books@[EMAIL PROTECTED]   2008-05-12 03:05:39 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Thu Jul 24 2:02:32 CDT 2008.