NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package db.pack;

import android.provider.BaseColumns;

public interface Constants extends BaseColumns

{
public static final String tname="LoginTBl"; // create table name
public static final String un="UNAME"; // create user name field
public static final String ps="Password"; // create password field

// this is Interface .. !!
}

----------------------------------------------
// class DBCreate
package db.pack;

import android.content.Context; // press Enter

import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import static db.pack.Constants.*; // add
import static android.provider.BaseColumns.*; // add


public class DBCreate extends SQLiteOpenHelper

{

public DBCreate(Context context)

{
super(context, "LoginDB", null, 1); // call super class SQLiteOpenHelper
// TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db)

{
// TODO Auto-generated method stub

db.execSQL("CREATE TABLE "+tname+"("+_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+un+" TEXT, "+ps+" TEXT);");

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)


{
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS "+tname);
onCreate(db);

}
}

---------------------------------------------------------
//Java MainActivity
package db.pack;

import android.os.Bundle; // press Enter

import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.widget.TextView;
import static db.pack.Constants.*; // add
import static android.provider.BaseColumns.*; // add
public class MainActivity extends Activity {
DBCreate dbc; //add
public static String[] from={_ID,un,ps}; // add



@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dbc=new DBCreate(this);
try
{
addData();
readData();
Cursor cur=readData();
showData(cur); // show will display info of cursor

}

finally
{
dbc.close();
}

}

private void showData(Cursor cur)

{
// TODO Auto-generated method stub
StringBuilder sb=new StringBuilder();
while (cur.moveToNext())
{
long id=cur.getLong(0);
String u=cur.getString(1);
String p=cur.getString(2); // depend on number of fields that you have
sb.append(id).append(":").append(u).append("-").append(p).append("n"); // /n to go next line


}

TextView tv=(TextView)findViewById(R.id.textView2);
tv.setText(sb);

}

private Cursor readData()

{
// TODO Auto-generated method stub
SQLiteDatabase db=dbc.getReadableDatabase(); //add
Cursor cr=db.query(tname, from, null, null, null, null, null); //add
return cr; //add


}

private void addData()

{
// TODO Auto-generated method stub

// the code of insert is here

SQLiteDatabase db=dbc.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(un, "abc"); // put string , string
cv.put(ps, "123"); // put string , string
db.insertOrThrow(tname, null, cv); // insert orThrow option

// to add new record
cv.put(un, "xyz"); // put string , string
cv.put(ps, "567"); // put string , string
db.insertOrThrow(tname, null, cv); // insert orThrow option

}

@Override
public boolean onCreateOptionsMenu(Menu menu) // this is method

{
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.