Hi Conny,
I have never used ARRAY type (and never will :)
But few things come to my mind immediately.
First how does H2 know that you have an array of integers?
In the table definition you only say ARRAY.
Maybe it is an ARRAY of bytes or cars or .. whatever
Most likely it is an array of objects.
And hey that's exactly what the error message says!
Why don't you just model your data like this:
create table userdata(userid int primary key);
create table friends(friendid int primary key, userid int references
userdata(userid));
Now you can set constraints better to values and know your types better.
This foolery with arrays in the relational database is just asking for
trouble.
(Yes I know, I am being provocative).
- rami
On 17.6.2011 1:13, [email protected] wrote:
Hi everybody,
I saw there is ARRAY data type, so I try to use it. But I have 2 problems.
I created a table at first: create table userdata(userid int, friends
ARRAY)
1) Then, I want to insert to records:
String query = "insert into userdata values(?, ?)";
PreparedStatement prep = conn.prepareStatement(query);
prep.setInt(1, 2);
prep.setObject(2, new int[] { 4, 5, 6 });
prep.addBatch();
prep.setInt(1, 3);
prep.setObject(2, new int[] { 3, 3, 3 });
prep.addBatch();
prep.execute();
But, I can just insert the last record. The first record is missing. I
don't know why...
2) The second problem is I can't read the array.
Statement stat = conn.createStatement();
String query = "select * from userdata";
ResultSet rs;
rs = stat.executeQuery(query);
rs.first();
int[] ar = (int[])rs.getObject(2);
Then I got the error Message: [Ljava.lang.Object; cannot be cast to [I
Can someone help me?
Thank you very much!
Conny
--
You received this message because you are subscribed to the Google
Groups "H2 Database" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/h2-database/-/qokF3f6ZtxcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.