Jump to content
Changes to the Jaspersoft community edition download ×

Insert list of values directly on database


ktrinad

Recommended Posts

By: flavio - flavio_toledo

Insert list of values directly on database

2006-07-13 07:03

People,

I need make a list of values with up to 300 itens.

I've this itens in a table of database and i'll insert this into table "listofvaluesitem", but i don't know how to this it with field "value" of table "listofvaluesitem", because this field has a type tinyblob.

do you know kow i make this?

Thank you,

Flávio

 

 

By: Teodor Danciu - teodord

RE: Insert list of values directly on databas

2006-07-13 07:46

 

Hi,

 

In the future version of JI we'll have support

for list input controls backed by a query.

So instead of recreating the items you could

query the exising table that you have.

 

Thank you,

Teodor

 

 

 

By: flavio - flavio_toledo

RE: Insert list of values directly on database

2006-07-13 10:56

Teodor,

I´ll make this by you said. I'll think in extract the data from my table and insert it into the table "listofvaluesitem" of jasperserver database, but i don't know kow insert the values into field "value", because the type of this field (tinyblob) and the type of my field is varchar. Is there a function for make this?

 

Thank you,

Flávio

 

 

By: Lucian Chirita - lucianc

RE: Insert list of values directly on databas

2006-07-14 02:11

You'd need to write a small Java utility to do this, as the data saved into the "value" column is a serialized Java object.

 

What you'd need to do is to query your table, read the value into a java.lang.String object, serialize it and save the serialized binary data into the "value" column.

 

Regards,

Lucian

 

 

By: flavio - flavio_toledo

RE: Insert list of values directly on databas

2006-07-14 05:06

Thanks for the information, i'll make this.

 

Regards,

Flávio

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Out of curiosity, are all serialized objects Strings? Or is there database structure documentation that I could look at?

 

I had the same idea re: inserting lists of values with a utility program, since that functionality isn't available yet.

 

I was trying to dig through the hibernate xml code, but it just says serialized type, without specifying a java type. (As you can probably tell, I'm not very familiar with hibernate.)

Link to comment
Share on other sites

I am using this code to store serialized String objects:

 

 

public String serialize(Object str)

{

java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();

try

{

java.io.ObjectOutputStream objectOut = new java.io.ObjectOutputStream(baos);

objectOut.writeObject(str);

 

}

catch(Exception e)

{

}

 

byte[] buffer = baos.toByteArray();

return byteToHex(buffer);

 

}

 

public String byteToHex(byte[] inBytes)

{

return byteToHex(inBytes,0,inBytes.length);

}

 

public String byteToHex(byte[] inBytes,int startIndex,int endIndex)

{

byte newByte = 0x00;

int i,hexIndex;

String hexChars = "0123456789ABCDEF";

 

StringBuffer outBuffer = new StringBuffer(endIndex - startIndex);

 

if ( inBytes == null || endIndex <= startIndex ) return (String)null;

for ( i = startIndex; i < endIndex; i++)

{

 

/*

* Each Hexadecimal character represents 4 bits and each element of

* the byte array represents 8 bits. First strip off the left 4

* bits, shift to the least significant (right) portion of a new

* byte, then mask the upper portion to allow proper conversion to an

* integer between 0 and 15. This value can be used as the index into

* the hexadecimal character string.

*/

 

newByte = (byte)(inBytes & 0xF0);

newByte = (byte)(newByte >>> 4);

newByte = (byte)(newByte & 0x0F);

hexIndex = (int)newByte;

outBuffer.append(hexChars.substring(hexIndex,hexIndex + 1));

 

/*

* Now strip off the right 4 bits, shift and convert to an integer

* between 0 and 15.

*/

 

newByte = (byte)(inBytes & 0x0F);

hexIndex = (int)newByte;

outBuffer.append(hexChars.substring(hexIndex,hexIndex + 1));

 

}

 

return outBuffer.toString();

 

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...