Обсуждение: JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar

Поиск
Список
Период
Сортировка

JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar

От
Michael musset
Дата:
Hi,

I'm having trouble of inserting an SQLXML  in my Postgresql 8.4 database :

java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4SQLXML cannot be cast to [B
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRowBuffer(AbstractJdbc2ResultSet.java:1729)
at org.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRow(AbstractJdbc2ResultSet.java:1291)

when i use that :

SQLXML sqlxml = con.createSQLXML();
DOMResult domResult=sqlxml.setResult(DOMResult.class)
domResult.setNode(xmldocumentDOM);

stmt.setSQLXML(1, sqlxml);
stmt.execute();

Do you have an idea, why ?



Thank you very much for your futur help :)

Re: JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar

От
Kris Jurka
Дата:

On Tue, 19 Oct 2010, Michael musset wrote:

> java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4SQLXML cannot be
> cast to [B
> atorg.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRowBuffer(AbstractJdbc2Re
> sultSet.java:1729)
> atorg.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRow(AbstractJdbc2ResultSe
> t.java:1291)
>
> SQLXML sqlxml = con.createSQLXML();
> DOMResult domResult=sqlxml.setResult(DOMResult.class)
> domResult.setNode(xmldocumentDOM);
>
> stmt.setSQLXML(1, sqlxml);
> stmt.execute();
>

Your sample code and stacktrace don't seem to match, but I see what the
problem is.  The updatable ResultSet code isn't prepared for handling a
SQLXML object.  It's slightly tricky to fix because the code in question
is in a JDBC2 class while SQLXML is JDBC4 only.  I'll look into it.

Kris Jurka

Fwd: JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar

От
Michael musset
Дата:


---------- Forwarded message ----------
From: Michael musset <mickamusset@gmail.com>
Date: Thu, Oct 21, 2010 at 10:26 AM
Subject: Re: [JDBC] JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar
To: Kris Jurka <books@ejurka.com>


Thank you very much, and about that :

Yes the bug appeared when I do an updaterow() to the resultset.


i've decided to migrate to postgresql 9.

will it work with JDBC4 Postgresql Driver, Version 9.0-801 ?

thanks,


On Thu, Oct 21, 2010 at 10:21 AM, Kris Jurka <books@ejurka.com> wrote:


On Tue, 19 Oct 2010, Michael musset wrote:

java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4SQLXML cannot be
cast to [B
atorg.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRowBuffer(AbstractJdbc2Re
sultSet.java:1729)
atorg.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRow(AbstractJdbc2ResultSe
t.java:1291)


SQLXML sqlxml = con.createSQLXML();
DOMResult domResult=sqlxml.setResult(DOMResult.class)
domResult.setNode(xmldocumentDOM);

stmt.setSQLXML(1, sqlxml);
stmt.execute();


Your sample code and stacktrace don't seem to match, but I see what the problem is.  The updatable ResultSet code isn't prepared for handling a SQLXML object.  It's slightly tricky to fix because the code in question is in a JDBC2 class while SQLXML is JDBC4 only.  I'll look into it.

Kris Jurka



--
Michael Musset,
Tel: 06 26 06 29 89




--
Michael Musset,
Tel: 06 26 06 29 89

Re: JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar

От
Michael musset
Дата:
So, what I have to do ?

i've tried to convert my xml into String but it still doesn't work :

ret.updateString("DATA", myXmlString);


the error appear when i did a updaterow in my resultset


the error is:

org.postgresql.util.PSQLException: ERROR: column "DATA" is of type xml but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.


how can i do that ?

thanks for the help,

On Thu, Oct 21, 2010 at 10:27 AM, Kris Jurka <jurka@ejurka.com> wrote:

No it won't work with the 9.0 JDBC driver either.  The same problem exists in both versions.

Kris


On 10/21/2010 1:26 AM, Michael musset wrote:
Thank you very much, and about that :

Yes the bug appeared when I do an updaterow() to the resultset.


i've decided to migrate to postgresql 9.

will it work with JDBC4 Postgresql Driver, Version 9.0-801
<http://jdbc.postgresql.org/download/postgresql-9.0-801.jdbc4.jar> ?


thanks,

On Thu, Oct 21, 2010 at 10:21 AM, Kris Jurka <books@ejurka.com
<mailto:books@ejurka.com>> wrote:



   On Tue, 19 Oct 2010, Michael musset wrote:

       java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4SQLXML
       cannot be
       cast to [B
       atorg.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRowBuffer(AbstractJdbc2Re
       sultSet.java:1729)
       atorg.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRow(AbstractJdbc2ResultSe
       t.java:1291)


       SQLXML sqlxml = con.createSQLXML();
       DOMResult domResult=sqlxml.setResult(DOMResult.class)
       domResult.setNode(xmldocumentDOM);

       stmt.setSQLXML(1, sqlxml);
       stmt.execute();


   Your sample code and stacktrace don't seem to match, but I see what
   the problem is.  The updatable ResultSet code isn't prepared for
   handling a SQLXML object.  It's slightly tricky to fix because the
   code in question is in a JDBC2 class while SQLXML is JDBC4 only.
     I'll look into it.

   Kris Jurka




--
Michael Musset,
Tel: 06 26 06 29 89




--
Michael Musset,
Tel: 06 26 06 29 89

Re: JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar

От
Craig Ringer
Дата:
On 23/10/2010 11:53 AM, Michael musset wrote:
> So, what I have to do ?
>
> i've tried to convert my xml into String but it still doesn't work :
>
> ret.updateString("DATA", myXmlString);
>
>
> the error appear when i did a updaterow in my resultset
>
>
> the error is:
>
> org.postgresql.util.PSQLException: ERROR: column "DATA" is of type xml
> but expression is of type character varying
>    Hint: You will need to rewrite or cast the expression.

It's one of those irritating areas where PostgreSQL's overzealous
refusal to cast ::text or ::varchar for interpretation as literals of
another type bites you.

You need to use updateObject("DATA", java.sql.Types.SQLXML) so the JDBC
driver knows what type to specify.

--
Craig Ringer

Tech-related writing at http://soapyfrogs.blogspot.com/

Re: JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar

От
Michael musset
Дата:
Thanks,

sorry for my poor level in Java/JDBC :

but how do you use that ?

i've tried :

ret.updateObject("DATA",writer.toString() ,java.sql.Types.SQLXML);

but it's still doesn't work :

ERROR: column "DATA" is of type xml but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.


neither this one :

ret.updateObject("DATA",(java.sql.Types.SQLXML)writer.toString());


sorry,

On Sat, Oct 23, 2010 at 6:09 AM, Craig Ringer <craig@postnewspapers.com.au> wrote:
On 23/10/2010 11:53 AM, Michael musset wrote:
So, what I have to do ?

i've tried to convert my xml into String but it still doesn't work :

ret.updateString("DATA", myXmlString);


the error appear when i did a updaterow in my resultset


the error is:

org.postgresql.util.PSQLException: ERROR: column "DATA" is of type xml
but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.

It's one of those irritating areas where PostgreSQL's overzealous refusal to cast ::text or ::varchar for interpretation as literals of another type bites you.

You need to use updateObject("DATA", java.sql.Types.SQLXML) so the JDBC driver knows what type to specify.

--
Craig Ringer

Tech-related writing at http://soapyfrogs.blogspot.com/

Re: JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar

От
Michael musset
Дата:
Ok, this one is a little bit stupid :

ret.updateObject("DATA",(java.sql.Types.SQLXML)writer.toString());  


by the way, i'm using :

/postgresql-9.0-801.jdbc4.jar ( i thought that it is better to use postgresql 9 )

thx,


On Sat, Oct 23, 2010 at 6:20 AM, Michael musset <mickamusset@gmail.com> wrote:
Thanks,

sorry for my poor level in Java/JDBC :

but how do you use that ?

i've tried :

ret.updateObject("DATA",writer.toString() ,java.sql.Types.SQLXML);

but it's still doesn't work :


ERROR: column "DATA" is of type xml but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.


neither this one :

ret.updateObject("DATA",(java.sql.Types.SQLXML)writer.toString());


sorry,


On Sat, Oct 23, 2010 at 6:09 AM, Craig Ringer <craig@postnewspapers.com.au> wrote:
On 23/10/2010 11:53 AM, Michael musset wrote:
So, what I have to do ?

i've tried to convert my xml into String but it still doesn't work :

ret.updateString("DATA", myXmlString);


the error appear when i did a updaterow in my resultset


the error is:

org.postgresql.util.PSQLException: ERROR: column "DATA" is of type xml
but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.

It's one of those irritating areas where PostgreSQL's overzealous refusal to cast ::text or ::varchar for interpretation as literals of another type bites you.

You need to use updateObject("DATA", java.sql.Types.SQLXML) so the JDBC driver knows what type to specify.

--
Craig Ringer

Tech-related writing at http://soapyfrogs.blogspot.com/




--
Michael Musset,
Tel: 06 26 06 29 89

Re: JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar

От
Kris Jurka
Дата:
On Sat, 23 Oct 2010, Craig Ringer wrote:

> You need to use updateObject("DATA", java.sql.Types.SQLXML) so the JDBC
> driver knows what type to specify.
>

That's not the API for update object.  There isn't a type parameter, the
variant with a third int parameter is a scale for numeric data.

Kris Jurka

Re: JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar

От
Kris Jurka
Дата:

On Thu, 21 Oct 2010, Kris Jurka wrote:

> On Tue, 19 Oct 2010, Michael musset wrote:
>
>> java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4SQLXML cannot be
>> cast to [B
>> atorg.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRowBuffer(AbstractJdbc2Re
>> sultSet.java:1729)
>> atorg.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRow(AbstractJdbc2ResultSe
>> t.java:1291)
>>
>> SQLXML sqlxml = con.createSQLXML();
>> DOMResult domResult=sqlxml.setResult(DOMResult.class)
>> domResult.setNode(xmldocumentDOM);
>>
>> stmt.setSQLXML(1, sqlxml);
>> stmt.execute();
>>
>
> Your sample code and stacktrace don't seem to match, but I see what the
> problem is.  The updatable ResultSet code isn't prepared for handling a
> SQLXML object.  It's slightly tricky to fix because the code in question is
> in a JDBC2 class while SQLXML is JDBC4 only.  I'll look into it.
>

I've put a fix for this into CVS.  I've uploaded a new jar file here:

http://ejurka.com/pgsql/jars/xml/

Kris Jurka

Re: JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar

От
Michael musset
Дата:
THANK YOU !

On Sat, Oct 23, 2010 at 8:25 AM, Kris Jurka <books@ejurka.com> wrote:


On Thu, 21 Oct 2010, Kris Jurka wrote:

On Tue, 19 Oct 2010, Michael musset wrote:

java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4SQLXML cannot be
cast to [B
atorg.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRowBuffer(AbstractJdbc2Re
sultSet.java:1729)
atorg.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRow(AbstractJdbc2ResultSe
t.java:1291)

SQLXML sqlxml = con.createSQLXML();
DOMResult domResult=sqlxml.setResult(DOMResult.class)
domResult.setNode(xmldocumentDOM);

stmt.setSQLXML(1, sqlxml);
stmt.execute();


Your sample code and stacktrace don't seem to match, but I see what the problem is.  The updatable ResultSet code isn't prepared for handling a SQLXML object.  It's slightly tricky to fix because the code in question is in a JDBC2 class while SQLXML is JDBC4 only.  I'll look into it.


I've put a fix for this into CVS.  I've uploaded a new jar file here:

http://ejurka.com/pgsql/jars/xml/

Kris Jurka



--
Michael Musset,
Tel: 06 26 06 29 89

Re: JDBC4 with SQLXML and postgresql-8.4-702.jdbc4.jar

От
Michael musset
Дата:
One thing that i regret about SQLXML object, is that you can't do at the same time :


1) get an SQLXML Object from a resultset
2) modify It
3) update the SQLXML Object to the resultset
4) updaterow


I've tried this :

// retrieve an SQLXML object from the ResultSet:
SQLXML sqlxml = resultSet.getSQLXML(1); // 1 is the column index 
// obtain DOM tree from SQLXML object:
DOMSource source = sqlxml.getSource(DOMSource.class); 
 
// create document object from DOMSource:
Document document = (Document) source.getNode();

modify the document here

resultSet.setSQLXML(1,sqlxml );
resultSet.updaterow();




but it doesn't work.

If someone is interesting about getting data and updating data in xml.

my method is to get a string from my xml.
parse it
modify the data

and :


SQLXML sqlxml = con.createSQLXML();
DOMResult domResult=sqlxml.setResult(DOMResult.class)
domResult.setNode(xmldocumentDOM); 
stmt.setSQLXML(1, sqlxml);
stmt.execute();

It's work .... but it's not beautiful ......



anyway, thank for the help !






On Sat, Oct 23, 2010 at 8:25 AM, Kris Jurka <books@ejurka.com> wrote:


On Thu, 21 Oct 2010, Kris Jurka wrote:

On Tue, 19 Oct 2010, Michael musset wrote:

java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4SQLXML cannot be
cast to [B
atorg.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRowBuffer(AbstractJdbc2Re
sultSet.java:1729)
atorg.postgresql.jdbc2.AbstractJdbc2ResultSet.updateRow(AbstractJdbc2ResultSe
t.java:1291)

SQLXML sqlxml = con.createSQLXML();
DOMResult domResult=sqlxml.setResult(DOMResult.class)
domResult.setNode(xmldocumentDOM);

stmt.setSQLXML(1, sqlxml);
stmt.execute();


Your sample code and stacktrace don't seem to match, but I see what the problem is.  The updatable ResultSet code isn't prepared for handling a SQLXML object.  It's slightly tricky to fix because the code in question is in a JDBC2 class while SQLXML is JDBC4 only.  I'll look into it.


I've put a fix for this into CVS.  I've uploaded a new jar file here:

http://ejurka.com/pgsql/jars/xml/

Kris Jurka



--
Michael Musset,
Tel: 06 26 06 29 89