Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 22
Registered: ‎05-14-2012
My Device: bold 9700
My Carrier: vodafone

Sqlite Multiple insert

Hi ,

 

I try to multiple data insert in Sqlite.

 

st=d1.createStatement("INSERT INTO t2e(id,kelime,anlam) SELECT "+String.valueOf(count)+",'aa','bbbb' UNION SELECT "+String.valueOf(count+23)+",'bbb','ccc' UNION SELECT "+String.valueOf(count+24)+",'aaaaa', 'bbb'");

 

This is OK but Same Content string couldn't work.So I tried to:

 

String response=getStringFromStream(httpInput, "UTF-8");

st=d1.createStatement(response); 

This code didnt work.

What is the problem ? Any idea?

Contributor
Posts: 22
Registered: ‎05-14-2012
My Device: bold 9700
My Carrier: vodafone

Re: Sqlite Multiple insert

ANy idea?

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: Sqlite Multiple insert

Does it work when you are not using the UNION?

 

E.

Contributor
Posts: 22
Registered: ‎05-14-2012
My Device: bold 9700
My Carrier: vodafone

Re: Sqlite Multiple insert

 

Thank you for your interest.

 

I tried without union but same error : SQL logic error or database...

 

I tried to write sql directly

st=d1.createStatement("INSERT INTO t2e(id,kelime,anlam) SELECT "+String.valueOf(count)+",'aa','bbbb' UNION SELECT "+String.valueOf(count+23)+",'bbb','ccc' UNION SELECT "+String.valueOf(count+24)+",'aaaaa', 'bbb'");

this worked fine. 

But I tried to read from txt file same string so:

String response=getStringFromStream(httpInput, "UTF-8");

st=d1.createStatement(response); 

it didn't work. 

error : SQL logic error or database...

 

Sql query is same , I don't understand where is the problem . UTF-8 ? or other things?


Developer
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE
My Carrier: Vodafone NL

Re: Sqlite Multiple insert

The SQL is incorrect. There are plenty of online SQL validators.

Contributor
Posts: 22
Registered: ‎05-14-2012
My Device: bold 9700
My Carrier: vodafone

Re: Sqlite Multiple insert

Can you explain this ? Because :

st=d1.createStatement("INSERT INTO t2e(id,kelime,anlam) SELECT "+String.valueOf(count)+",'aa','bbbb' UNION SELECT "+String.valueOf(count+23)+",'bbb','ccc' UNION SELECT "+String.valueOf(count+24)+",'aaaaa', 'bbb'");

 

this worked fine. 

Developer
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE
My Carrier: Vodafone NL

Re: Sqlite Multiple insert

[ Edited ]

Wrong answer, please delete

 

I see the SELECT keyword but I don't see FROM keyword. Question why it's not throwing any exception. Probably because you don't call prepare method for the Statement.

 

Here are severl online resources with SQL syntax:

http://www.w3schools.com/sql/sql_insert.asp

http://www.techonthenet.com/sql/insert.php

 

Here is online SQL validator:

http://developer.mimer.com/validator/parser200x/index.tml#parser

 

Here is tutorail how to use SQLite on the BB:

http://docs.blackberry.com/en/developers/deliverables/8682/Code_samples_702046_11.jsp

 

I'm really sad that I have to search Google for you. It's really easy.

Contributor
Posts: 22
Registered: ‎05-14-2012
My Device: bold 9700
My Carrier: vodafone

Re: Sqlite Multiple insert

I mean this query is correct and worked.Not need to FROM after SELECT.

INSERT INTO t2e(id,kelime,anlam) SELECT 1,'aa','bbbb' UNION SELECT 2,'bbb','ccc' UNION SELECT 3,'aaa', 'bbb'

 

But When I try to read same query from txt file , I recieve SQL Logic Error

Developer
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE
My Carrier: Vodafone NL

Re: Sqlite Multiple insert

[ Edited ]

Wrong answer, please delete

 

Nice. This is my last post in this thread.

 

http://en.wikipedia.org/wiki/Select_(SQL)

SELECT statement retrieves zero or more rows from one or more database tables or database views

Contributor
Posts: 22
Registered: ‎05-14-2012
My Device: bold 9700
My Carrier: vodafone

Re: Sqlite Multiple insert

INSERT INTO t2e(id,kelime,anlam) SELECT 1,'aa','bbbb' UNION SELECT 2,'bbb','ccc' UNION SELECT 3,'aaa', 'bbb'

 

try this ok? Then say it is working or not ? 

 

every SQL syntax is not same. For example in PostgreSQL you can use "SELECT 1,2,3"   but in ORACLE you should use "SELECT 1,2,3 FROM dual"