If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
Developer
lynxgeek
Posts: 272
Registered: ‎05-24-2010
My Device: DEV Alpha C & BB 9720
My Carrier: Idea and Airtel

Problem with SqlLite .....

Hi everyone.

 

 

When i am trying to prepare the Sql Insert statement its getting strucked..and its showing ...

 

in the Eclipse Editor its showing Sql lite pending text...

 

can any one help me...

 

 

thanks regards

yakub pasha..

Please use plain text.
Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Problem with SqlLite .....

What is Ur Insert statement.

Please use plain text.
Developer
lynxgeek
Posts: 272
Registered: ‎05-24-2010
My Device: DEV Alpha C & BB 9720
My Carrier: Idea and Airtel

Re: Problem with SqlLite .....

this is the method ...

 

when control reaches to the red marked statement...

 

 

 

public boolean insertfavoriteRecord(String appid){

try{
StringBuffer sb = new StringBuffer();
sb.append("INSERT INTO Favorites(appid)");
sb.append("VALUES ('"+appid);
sb.append("')");
String query = sb.toString();

Statement statement = this.db.createStatement(query);
statement.prepare();   //here the control getting suspended..
statement.execute();
statement.close();

}catch (Exception e) {
return false;
}
return true;

}

 

 

thank you

regards yakub pasha

Please use plain text.
Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Problem with SqlLite .....

Use Like this.

 

        Database d=null;
        URI uri=null;
        try
        {
            uri=URI.create("file:///SDCard/Databases/MyDatabase.db");
        }catch(Exception r){}
        if(f==insert)
        {
            try
            {
                d=DatabaseFactory.open(uri);
                Statement st=d.createStatement("CREATE TABLE People(Name TEXT(20),Age NUMERIC NOT NULL)");
                st.prepare();
                st.execute();
                st.close();
                d.close();
            }catch(Exception e)
            {
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
            Dialog.alert("Table Created");
        }
        
        if(f==record)
        {
            try
            {
                d=DatabaseFactory.open(uri);
                Statement st=d.createStatement("INSERT INTO People(Name,Age) VALUES('Mat Demon',28)");
                st.prepare();
                st.execute();
                st.close();

            }

          }

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Problem with SqlLite .....

Try this instead:

 

public boolean insertfavoriteRecord(String appid) {

  try{
    Statement statement = this.db.createStatement(
        "INSERT INTO Favorites(appid) VALUES (?)"
        );
    statement.prepare();   //here the control getting suspended..
    statement.bind(1, appid);
    statement.execute();
    statement.close();

  } catch (Exception e) {
    return false;
  }
  return true;
}

Interpolating the value of appid directly into the statement can, depending on the value, turn the statement into illegal SQL. Using bind() avoids that problem.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.