0

In my application I have store the text in string and one parameter is byte array form I have get the data but in byte array form index data are show in toast all data are show in string form but last data are show in byte array form [B@436ac990 and if next time I click show button and appear toast they vary byte array [B@436ac991 and they vary again and again how to show in string form i know this is memory address but how to convert into string.if I wrong please solve my query

This is my mainactivity class

public class MainActivity extends Activity {
    EditText F_name, L_name, Mob_num, Email_Add, Repeat_email, password;
    DBHelper db;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        db = new DBHelper(this);

        F_name = (EditText) findViewById(R.id.F_name);
        L_name = (EditText) findViewById(R.id.L_name);
        Mob_num = (EditText) findViewById(R.id.mobile_no);
        Email_Add = (EditText) findViewById(R.id.E_address);
        Repeat_email = (EditText) findViewById(R.id.repet_Email_address);
        password = (EditText) findViewById(R.id.password);

        // EditText F_name=(EditText)findViewById(R.id.F_name);
        Button save = (Button) findViewById(R.id.save);
        save.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                String first_name = F_name.getText().toString();
                String Last_name = L_name.getText().toString();
                String Mobile_numb = Mob_num.getText().toString();
                String Emailadd = Email_Add.getText().toString();
                String Repeat_email_add = Repeat_email.getText().toString();
                byte[] Passwwrd = password.getText().toString().getBytes();
                // String pasS=new String(Passwwrd);

                db.openToWrite();

                long id = db.insert(first_name, Last_name, Mobile_numb, Emailadd, Repeat_email_add, Passwwrd);

                db.close();
            }

        });

        Button Show = (Button) findViewById(R.id.show);
        Show.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                db.openToRead();
                Cursor c = db.fetch_all();

                if (c.moveToFirst()) {
                    do {
                        DisplayContact(c);
                    } while (c.moveToNext());
                }
                db.close();

            }
        });

    }

    public void DisplayContact(Cursor c) {
        Toast.makeText(
                this,
                "FirstName: " + c.getString(0) + "\n" + "Lastname: " + c.getString(1) + "\n" + "Mobile_numb: " + c.getString(2) + "\n" + "Emailadd: "
                        + c.getString(3) + "\n" + "Repeat_email_add: " + c.getString(4) + "\n" + "password: " + c.getBlob(5) + "\n", Toast.LENGTH_LONG).show();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

This is my dbhelper class

package com.example.dbhelpe;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper {

    public static final String MYDATABASE_NAME = "property_detail.db";

    public static final String MYDATABASE_TABLE = "registration_table";

    public static final String MYDATABASE_TABLE_1 = "deatil_table";

    public static final String MYDATABASE_TABLE_2 = "Groups_table";

    public static final int MYDATABASE_VERSION = 1;

    public static final String ID = "_id";

    private static final String FIRST_NAME = "firstname"; // a column named
                                                            // "_id" is required
                                                            // for cursor
    private static final String LAST_NAME = "lastname";
    private static final String MOBILE_NO = "mobileno";
    private static final String EMAIL_ADDRESS = "emailaddress";
    private static final String REPEAT_EMAIL_ADDRESS = "remailaddress";
    private static final String PASSWORD = "password";

    private static final String OWNER = "owner"; // a column named "_id" is
                                                    // required for cursor
    private static final String ADDRESS = "address";
    private static final String CASH = "cash";
    private static final String REPORTED_BY = "reportedby";
    private static final String DATE = "date";
    private static final String PROPERTY_ID = "propertyid";

    private static final String COMGROUP_NAME = "comgroup_name"; // a column
                                                                    // named
                                                                    // "_id" is
                                                                    // required
                                                                    // for
                                                                    // cursor
    private static final String NODE_NAME = "node_name";
    private static final String LICENSE_COUNT = "license_count";
    private static final String NODE_MAC_ADDRESS = "node_mac_address";

    private SQLiteHelper sqLiteHelper;

    private static SQLiteDatabase sqLiteDatabase;

    private Context context;

    private static final String SCRIPT_CREATE_DATABASE = "create table " + MYDATABASE_TABLE + " (" + ID + " integer primary key autoincrement, " + FIRST_NAME
            + " text not null," + LAST_NAME + " text not null," + MOBILE_NO + " text not null, " + EMAIL_ADDRESS + " text not null, " + REPEAT_EMAIL_ADDRESS
            + " text not null, " + PASSWORD + " text not null);";

    private static final String SCRIPT_CREATE_DATABASE1 = "create table " + MYDATABASE_TABLE_1 + " (" + ID + " integer primary key autoincrement, " + OWNER
            + " text not null," + ADDRESS + " text not null," + CASH + " text not null," + REPORTED_BY + " text not null," + DATE + " text not null,"
            + PROPERTY_ID + " text not null);";

    private static final String SCRIPT_CREATE_DATABASE2 = "create table " + MYDATABASE_TABLE_2 + " (" + ID + " integer primary key autoincrement, "
            + COMGROUP_NAME + " text not null," + NODE_NAME + " text not null," + LICENSE_COUNT + " text not null," + NODE_MAC_ADDRESS + " text not null);";

    // private static final String SCRIPT_CREATE_DATABASE_1 =
    // "create table " + MYDATABASE_TABLE_1 + " ("
    // + ID + " integer primary key autoincrement, "
    // + SMS1 + " text not null);";
    //
    // private static final String SCRIPT_CREATE_DATABASE_2 =
    // "create table " + MYDATABASE_TABLE_2 + " ("
    // + ID + " integer primary key autoincrement, "
    // + VALUE + " integer not null);";

    public DBHelper(Context c) {
        context = c;

    }

    public DBHelper openToRead() throws android.database.SQLException {

        sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null, MYDATABASE_VERSION);

        sqLiteDatabase = sqLiteHelper.getReadableDatabase();

        return this;
    }

    public DBHelper openToWrite() throws android.database.SQLException {

        sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME, null, MYDATABASE_VERSION);

        sqLiteDatabase = sqLiteHelper.getWritableDatabase();

        return this;
    }

    public void close() {

        sqLiteHelper.close();
    }

    public long insert(String owner, String address, String cash, String reportedby, String date, byte[] passwwrd) {

        ContentValues contentValues = new ContentValues();

        contentValues.put(OWNER, owner);
        contentValues.put(ADDRESS, address);
        contentValues.put(PROPERTY_ID, passwwrd);
        contentValues.put(DATE, date);
        contentValues.put(REPORTED_BY, reportedby);
        contentValues.put(CASH, cash);

        return sqLiteDatabase.insert(MYDATABASE_TABLE_1, null, contentValues);
    }

    public long insert_register(String firstname, String lastname, String mobileno, String emailaddress, String remailaddress, String password) {

        ContentValues contentValues = new ContentValues();

        contentValues.put(FIRST_NAME, firstname);
        contentValues.put(LAST_NAME, lastname);
        contentValues.put(MOBILE_NO, mobileno);
        contentValues.put(EMAIL_ADDRESS, emailaddress);
        contentValues.put(REPEAT_EMAIL_ADDRESS, remailaddress);
        contentValues.put(PASSWORD, password);

        return sqLiteDatabase.insert(MYDATABASE_TABLE, null, contentValues);
    }

    public Cursor fetch_all() {

        String[] columns = new String[] { OWNER, ADDRESS, CASH, REPORTED_BY, DATE, PROPERTY_ID };

        Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE_1, columns, null, null, null, null, null);

        return cursor;
    }

    // public long update_communication(String id,String cast,String port,String
    // broadcast,String unicast,String multicast){
    //
    // ContentValues contentValues = new ContentValues();
    //
    // // contentValues.put(LISTID, k);
    //
    // contentValues.put(ID, id);
    // contentValues.put(PORT, port);
    // contentValues.put(CAST_TYPE, cast);
    // contentValues.put(BROADCAST_ADDRESS, broadcast);
    // contentValues.put(UNICAST_ADDRESS, unicast);
    // contentValues.put(MULTICAST_ADDRESS, multicast);
    // return sqLiteDatabase.update(MYDATABASE_TABLE, contentValues, null,
    // null);
    // // return sqLiteDatabase.insert(MYDATABASE_TABLE_1, null, contentValues);
    // }

    // public long update_audio(String id,String codecbitrate,String
    // codecstatus,String echostatus){
    //
    // ContentValues contentValues = new ContentValues();
    //
    // // contentValues.put(LISTID, k);
    //
    // contentValues.put(ID, id);
    // contentValues.put(CODEC_BIT_RATE, codecbitrate);
    // contentValues.put(CODEC_STATUS, codecstatus);
    // contentValues.put(ECHO_STATUS, echostatus);
    // return sqLiteDatabase.update(MYDATABASE_TABLE_1, contentValues, null,
    // null);
    // // return sqLiteDatabase.insert(MYDATABASE_TABLE_1, null, contentValues);
    // }

    // public long insert2(int value){
    //
    // ContentValues contentValues = new ContentValues();
    //
    // contentValues.put(VALUE, value);
    //
    // return sqLiteDatabase.insert(MYDATABASE_TABLE_2, null, contentValues);
    // }
    //
    // public boolean deleterow(String item){
    //
    // return sqLiteDatabase.delete(MYDATABASE_TABLE, SMS + "=?", new
    // String[]{item}) >0;
    // }

    public int deleteAll() {

        return sqLiteDatabase.delete(MYDATABASE_TABLE, null, null);
    }

    // public Cursor queueAll(){
    //
    // String[] columns = new
    // String[]{CAST_TYPE,BROADCAST_ADDRESS,PORT,UNICAST_ADDRESS,MULTICAST_ADDRESS};
    //
    // Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns,null,
    // null, null, null, null);
    //
    // return cursor;
    // }
    // public Cursor queueAll1(){
    //
    // String[] columns = new String[]{CODEC_STATUS,ECHO_STATUS,CODEC_BIT_RATE};
    //
    // Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE_1, columns,null,
    // null, null, null, null);
    //
    // return cursor;
    // }
    //
    // public Cursor queueAll2(){
    //
    // String[] columns = new String[]{VALUE};
    //
    // Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE_2, columns,null,
    // null, null, null, null);
    //
    // return cursor;
    // }

    // public void update_byID(String item){
    //
    // ContentValues values = new ContentValues();
    //
    // values.put(CAST_TYPE, item);
    // sqLiteDatabase.update(MYDATABASE_TABLE, values, null, null);
    // }

    // public void codec_update(String item){
    //
    // ContentValues values = new ContentValues();
    //
    // values.put(CODEC_STATUS, item);
    // sqLiteDatabase.update(MYDATABASE_TABLE_1, values, null, null);
    // }
    // public void codecbitrate_update(String item){
    //
    // ContentValues values = new ContentValues();
    //
    // values.put(CODEC_BIT_RATE, item);
    // sqLiteDatabase.update(MYDATABASE_TABLE_1, values, null, null);
    // }
    //
    // public void echo_update(String item){
    //
    // ContentValues values = new ContentValues();
    //
    // values.put(ECHO_STATUS, item);
    // sqLiteDatabase.update(MYDATABASE_TABLE_1, values, null, null);
    // }
    // public void port_update(String item){
    //
    // ContentValues values = new ContentValues();
    //
    // values.put(PORT, item);
    // sqLiteDatabase.update(MYDATABASE_TABLE, values, null, null);
    // }
    // public void broadcast_update(String item){
    //
    // ContentValues values = new ContentValues();
    //
    // values.put(BROADCAST_ADDRESS, item);
    // sqLiteDatabase.update(MYDATABASE_TABLE, values, null, null);
    // }
    // public void unicast_update(String item){
    //
    // ContentValues values = new ContentValues();
    //
    // values.put(UNICAST_ADDRESS, item);
    // sqLiteDatabase.update(MYDATABASE_TABLE, values, null, null);
    // }
    // public void multi_update(String item){
    //
    // ContentValues values = new ContentValues();
    //
    // values.put(MULTICAST_ADDRESS, item);
    // sqLiteDatabase.update(MYDATABASE_TABLE, values, null, null);
    // }
    // public void cast_update(String item){
    //
    // ContentValues values = new ContentValues();
    //
    // values.put(CAST_TYPE, item);
    // sqLiteDatabase.update(MYDATABASE_TABLE, values, null, null);
    // }

    // public Cursor insert_bySearch(String item){
    // String[] columns = new String[]{SMS};
    // Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns,SMS +"="+
    // item, null, null, null, null);
    // // sqLiteDatabase.update(MYDATABASE_TABLE, values, SMS +"="+ item ,
    // null);
    // return cursor ;
    // }

    public class SQLiteHelper extends SQLiteOpenHelper {

        private long l;
        private DBHelper myDB;

        public SQLiteHelper(Context context, String name, CursorFactory factory, int version) {

            super(context, name, factory, version);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {

            db.execSQL(SCRIPT_CREATE_DATABASE);
            db.execSQL(SCRIPT_CREATE_DATABASE1);
         // db.execSQL(SCRIPT_CREATE_DATABASE2);

            // db.execSQL("INSERT INTO " + MYDATABASE_TABLE
            // +" Values ('0','0','20938','255.255.255.255','192.168.1.154','239.5.5.5');");
            // db.execSQL("INSERT INTO " + MYDATABASE_TABLE_1
            // +" Values ('0','true','5','false');");
            // PreferenceConnector.writeString(context,
            // PreferenceConnector.NODE,"2");

        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO Auto-generated method stub

        }

    }

    public Cursor rawQueryNum() {
        Cursor cursor = sqLiteDatabase.query(true, MYDATABASE_TABLE, null, null, null, null, null, null, null);

        return cursor;
    }

    public Cursor rawQuery(String string, Object object) {
        // TODO Auto-generated method stub
        return null;
    }

}

this is XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/F_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="FIRST_NAME"
        android:text="" />

    <EditText
        android:id="@+id/L_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="LAST_NAME"
        android:text="" />

    <EditText
        android:id="@+id/mobile_no"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="MOBILE_NO"
        android:text="" />

    <EditText
        android:id="@+id/E_address"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="EMAIL_ADDRESS"
        android:text="" />

    <EditText
        android:id="@+id/repet_Email_address"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="REPEAT_EMAIL_ADDRESS"
        android:text="" />

    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="PASSWORD"
        android:text="" />

    <Button
        android:id="@+id/save"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="save" />
      <Button
        android:id="@+id/show"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SHOW" />

</LinearLayout>
5
  • do you want to save images in sqlite? Commented Dec 19, 2013 at 7:22
  • Can you tell me where are you getting problem to insert data. Commented Dec 19, 2013 at 7:24
  • Why is the password a byte array? If it's entered by the user, it is a string. Commented Dec 19, 2013 at 7:59
  • user entered in string form i have encrypt the byte array and decrypt but i have save in sqlitedatabase Commented Dec 19, 2013 at 8:46
  • if i get colomn of byte array than i got byte array,but how i change to string of colomn data any body have any example Commented Dec 20, 2013 at 8:47

1 Answer 1

1

To convert between a string and byte array, you must take charset encoding into account:

 String original = "some text";
 byte[] utf8buffer = sometext.getBytes("UTF8");
 String fromUtf8 = new String(utf8buffer, "UTF8");

See Byte Encodings and Strings and String.String (byte[], String).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.