Problem with insertion into SqLite Database..

by Raihan Jamal » Wed, 21 Apr 2010 06:22:00 GMT


Sponsored Links
 hanks for replying...
I am having one more problem now...
I am using this below java file to create a database and table on the
click event of Create DB Button[b][i]( till here it is working fine)[/
i] [/b]and then below this Create DB button, there is one more button
named Send Button... and on the click event of Send Button I am
opening another activity which contains a edit text and a button
called Insert[i][b](this is also working fine for me)[/b][/i] and on
the click event of this Insert Button... I have to insert the value
that we are typing into edit text box into the table that we have
created previously.... but I am not able to figure it out why it is
not inserting into table that we have created previously... what wrong
I am doing please let me know.... Below are the codes....
-----------------
[size=18]This Code contains Create DB Button and Send Button and click
event also that are creating tables and database
[/size]
[code]
package com.example.hw3;


import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class HW3 extends Activity {
private Button b1;
private Button b2;
@SuppressWarnings("unused")
private A1 test;
private EditText text;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (EditText) findViewById(R.id.EditText01);
initControls();
}

protected void initControls()
{
b1 = (Button)findViewById(R.id.CreateDB);
b2 = (Button)findViewById(R.id.Button02);





b1.setOnClickListener(new Button.OnClickListener()
{ public void onClick (View v){ DoWork(); }});

b2.setOnClickListener(new Button.OnClickListener()
{ public void onClick (View v){
Intent myIntent = new Intent(HW3.this, A1.class);
// HW3.this.startActivity(myIntent);
startActivity(myIntent);
}});


}


protected void DoWork()
{

// SQLiteDatabase db=null;

// db1 = new HW3DbAdapter(this);
text.setText("Button 1 was clicked");
// db1.open();
//fillData();

SQLiteDatabase myDB= null;
String TableName = "db_entry";

/* Create a Database. */
try {
myDB = this.openOrCreateDatabase("db_hw3", MODE_PRIVATE,
null);
myDB.execSQL("DROP TABLE IF EXISTS db_entry" );
/* Create a Table in the Database. */
myDB.execSQL("CREATE TABLE IF NOT EXISTS "
+ TableName
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, mb_text TEXT NOT
NULL,ph_location TEXT);");

}
catch(Exception e) {
Log.e("Error", "Error", e);
} finally {
if (myDB != null)
myDB.close();
}


}



} [/code]


------------------
[size=18]
This is the Code for an Activity that contain edit text and Insert
Button....I think something wrong I am doing in the try block of this
code..... Please help[/size]

[code] package com.exampl



Other Threads

1. ListView/ ScrollView : What exactly is happening in onInterceptTouchEvent()

I know that we are not supposed to put a listView inside of a
scrollView.  The layout  and nesting of my apps views are determined
at run time and I have no control over that.My situation demands it
and I have a working implementation to achieve that.  However I am not
sure what exactly is happening in  onInterceptTouchEvent().

I am returning false from onTouchEvent() ,of scrollView, if the
MotionEvent occurred within the bounds of the listView, thus the event
is passed down to my listView to handle. So if I touch and drag
outside the listView my outer scrollView scrolls, else if I touch and
drag on the listView, the listView scrolls. They dont compete for
scrolling anymore. This is all possible only if I always return false
from the  onInterceptTouchEvent() of the scrollView. In the default
implementation it returns true if it is being dragged. My solution
breaks if I return true from here for any condition. Is it ok to
simply return false all the time from  onInterceptTouchEvent()? I have
tried scrolling in several ways and both the scrollview and the
listView are scrolling as expected when I return false.

A standalone listView also works fine when I simply return false from
its onInterceptTouchEvent() instead of  returning  super(AbsListView).
onInterceptTouchEvent()

Anyone has any scenario when the scrolling might not work?

thanks,
vk

-- 

2. Weird Camera Intent behavior

Hi all.

I'm invoking the MediaStore.ACTION_IMAGE_CAPTURE intent with the
MediaStore.EXTRA_OUTPUT extra so that it does save the image to that
file.



On the onActivityResult I can check that the image is being saved in
the intended file, which is correct. The weird thing is that anyhow,
the image is also saved in a file named something like
"/sdcard/Pictures/Camera/1298041488657.jpg" (epoch time in which the
image was taken).

 I've checked the Camera app source (froyo-release branch) and I'm
*almost* sure that the code path is correct and wouldn't have to save
the image, but I'm a noob and I'm not completly sure. AFAIK, the image
saving process starts with this callback (comments are mine):

private final class JpegPictureCallback implements PictureCallback {
...
    public void onPictureTaken(...){
        ...
        // This is where the image is passed back to the invoking activity.
        mImageCapture.storeImage(jpegData, camera, mLocation);
        ...

        public void storeImage(final byte[] data,
                android.hardware.Camera camera, Location loc) {
            if (!mIsImageCaptureIntent) {      // Am i an intent?
                int degree = storeImage(data, loc); // THIS SHOULD NOT
BE CALLED WITHIN THE CAPTURE INTENT!!
             .......

       // An finally:
        private int storeImage(byte[] data, Location loc) {
            try {
                long dateTaken = System.currentTimeMillis();
                String title = createName(dateTaken);
                String filename = title + ".jpg";  // Eureka,
timestamp filename!
                 ...

So, I'm receiving the correct data, but it's also being saved in the
"storeImage(data, loc);" method call, which should not be called...


It'd not be a problem if I could get the newly created filename from
the intent result data, but I can't. When I found this out, I found
about 20 image files from my tests that I didn't know were on my
sdcard :)

I'm getting this behavior both with my Nexus One with Froyo and my
Huawei U8110 with Eclair.

Could please anyone enlight me? Dianne? ;)

Thanks a lot.

-- 

3. Which is the best way to implement double buffering?

4. Spaces in links to Android Developers reference

5. Problem with WebView

6. Honeycomb SDK

7. Does Android have a LinkButton. Basically like text but you click on it?