Thread: ResultSetMetaData problems (getColumnType() and -TypeName)

ResultSetMetaData problems (getColumnType() and -TypeName)

From
Þórhallur Hálfdánarson
Date:
<p><font size="2">Hi</font><p><font size="2">I've seen some postings on this subject since ages ago. The code and the
outputpretty much says what there has to be said (there was as example similar to this code somewhere). Sorry for the
Icelandic,though. :-)</font><p><font size="2"><code></font><br /><font size="2">int iFjoldi =
rsmd.getColumnCount();</font><br/><font size="2">System.out.println("Fjöldi dálka í töflunni sjálfri: "+
iFjoldi);</font><br/><font size="2">for (int i=1; i <= iFjoldi; i++)</font><br /><font size="2">{</font><br
/>       <font size="2">System.out.println("Dálkur "+ i);</font><br />        <font size="2">try</font><br />       
<fontsize="2">{</font><br />                <font size="2">rsmd = rs.getMetaData();</font><br />                <font
size="2">System.out.println("Dálkur"+ i +": "+ rsmd.getColumnType(i));</font><br />                <font
size="2">System.out.println("Dálkur"+ i +": "+ rsmd.getColumnTypeName(i));</font><br />                <font
size="2">System.out.println("Éger gimp");</font><br />        <font size="2">}</font><br />        <font size="2">catch
(SQLExceptione)</font><br />        <font size="2">{</font><br />                <font
size="2">System.out.println("FönkySQL Exception: "+ e.toString());</font><br />        <font size="2">}</font><br
/>       <font size="2">catch (Exception e)</font><br />        <font size="2">{</font><br />                <font
size="2">System.out.println("FönkyException: "+ e.toString());</font><br />                <font
size="2">e.printStackTrace();</font><br/>        <font size="2">}</font><br /><font size="2">}</font><br /><font
size="2"></code></font><p><fontsize="2"><output></font><br /><font size="2">Fjöldi dálka í töflunni
sjálfri:4</font><br /><font size="2">Dálkur 1</font><br /><font size="2">Fönky Exception:
java.lang.NullPointerException:</font><br /><font size="2">java.lang.NullPointerException: </font><br /><font
size="2">       at org.postgresql.Connection.ExecSQL(Connection.java:312)</font><br /><font size="2">        at
org.postgresql.Field.getSQLType(Field.java:79)</font><br/><font size="2">        at
org.postgresql.jdbc2.ResultSetMetaData.getColumnType(ResultSetMetaData.java:363)</font><br/><font size="2">        at
com.margmidlun.LIN.Upplysingakerfi.Importer.go(Importer.java:132)</font><br/><font size="2">        at
Gagnagaur.main(Gagnagaur.java:13)</font><br/><font size="2">Dálkur 2</font><br /><font size="2">Fönky Exception:
java.lang.NullPointerException:</font><br /><font size="2">java.lang.NullPointerException: </font><br /><font
size="2">       at org.postgresql.Connection.ExecSQL(Connection.java:312)</font><br /><font size="2">        at
org.postgresql.Field.getSQLType(Field.java:79)</font><br/><font size="2">        at
org.postgresql.jdbc2.ResultSetMetaData.getColumnType(ResultSetMetaData.java:363)</font><br/><font size="2">        at
com.margmidlun.LIN.Upplysingakerfi.Importer.go(Importer.java:132)</font><br/><font size="2">        at
Gagnagaur.main(Gagnagaur.java:13)</font><br/><font size="2">Dálkur 3</font><br /><font size="2">Fönky Exception:
java.lang.NullPointerException:</font><br /><font size="2">java.lang.NullPointerException: </font><br /><font
size="2">       at org.postgresql.Connection.ExecSQL(Connection.java:312)</font><br /><font size="2">        at
org.postgresql.Field.getSQLType(Field.java:79)</font><br/><font size="2">        at
org.postgresql.jdbc2.ResultSetMetaData.getColumnType(ResultSetMetaData.java:363)</font><br/><font size="2">        at
com.margmidlun.LIN.Upplysingakerfi.Importer.go(Importer.java:132)</font><br/><font size="2">        at
Gagnagaur.main(Gagnagaur.java:13)</font><br/><font size="2">Dálkur 4</font><br /><font size="2">Fönky Exception:
java.lang.NullPointerException:</font><br /><font size="2">java.lang.NullPointerException: </font><br /><font
size="2">       at org.postgresql.Connection.ExecSQL(Connection.java:312)</font><br /><font size="2">        at
org.postgresql.Field.getSQLType(Field.java:79)</font><br/><font size="2">        at
org.postgresql.jdbc2.ResultSetMetaData.getColumnType(ResultSetMetaData.java:363)</font><br/><font size="2">        at
com.margmidlun.LIN.Upplysingakerfi.Importer.go(Importer.java:132)</font><br/><font size="2">        at
Gagnagaur.main(Gagnagaur.java:13)</font><br/><font size="2"></output></font><br /><p><font size="2">The same has
shownup on setups:</font><br /><font size="2">Setup A)</font><br /><font size="2">  Machine S)</font><br /><font
size="2">   RedHat Linux 6.0</font><br /><font size="2">    PostgreSQL 6.5.1 (with JDBC, other stuff working
fine)</font><br/><font size="2">  Machine J)</font><br /><font size="2">    RedHat Linux 6.1</font><br /><font
size="2">    Sun JDK:</font><br /><font size="2">      java version "1.2.2"</font><br /><font size="2">      Classic VM
(build1.2.2-L, green threads, nojit)</font><br /><font size="2">    jdbc6.5-1.2.jar</font><p><font size="2">Setup
B)</font><br/><font size="2">  Machine T)</font><br /><font size="2">    RedHat Linux 6.2</font><br /><font
size="2">   PostgreSQL 7.0.2</font><br /><font size="2">      $ rpm -qa |grep postgres</font><br /><font size="2">     
postgresql-jdbc-7.0.2-2</font><br/><font size="2">      postgresql-odbc-7.0.2-2</font><br /><font size="2">     
postgresql-7.0.2-2</font><br/><font size="2">      postgresql-server-7.0.2-2</font><br /><font size="2">     
postgresql-devel-7.0.2-2</font><br/><font size="2">    Sun JDK</font><br /><br /><p><font size="2">Now.... do you have
anytips ?</font><br /><p><font size="2">Regards,</font><br /><font size="2">Tolli</font><br /><font
size="2">tolli@margmidlun.is</font>