Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7791007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:45:27+00:00 2026-06-01T21:45:27+00:00

I have created one table, but i want to create two and when i

  • 0

I have created one table, but i want to create two and when i hit the “show” button, i want to be able to select contents from both tables and show them…this is my code…am having problems creating two tables and showing them:

public class Entername extends Activity {

        private Button showButton;
        private Button insertButton;
        private TextView nameEditText;
        private TextView addTextView;
        private Button doneButton;
        public DatabaseHelper dbHelper = new DatabaseHelper(Entername.this,"pubgolfdatabase",2);
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.entername); 
            addTextView = (TextView)findViewById(R.id.textView1);
            doneButton= (Button)findViewById(R.id.doneButton);
            insertButton = (Button)findViewById(R.id.addButton);
            nameEditText = (EditText)findViewById(R.id.name);  
            showButton =(Button)findViewById(R.id.button1);
            showButton.setOnClickListener(new showButtonListener());
            insertButton.setOnClickListener(new InsertButtonListener());
            doneButton.setOnClickListener(new DoneButtonListener());

            /** create the database if it dosen't exist  **/
            SQLiteDatabase db = dbHelper.getWritableDatabase();
            try
            {
                db.execSQL("create table user_name(ID integer, name varchar(90));");                                    
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }           
        }

        class InsertButtonListener implements OnClickListener, android.view.View.OnClickListener
        {
            public void onClick(View v) 
            {                   
                if("".equals(nameEditText.getText().toString())) 
                {
                    Toast toast = Toast.makeText(Entername.this, "Sorry, you must input both the name and the address!", Toast.LENGTH_LONG); 
                    toast.show();
                }
                else
                {
                    long flag = 0;
                    int id = 1;
                    SQLiteDatabase db = dbHelper.getWritableDatabase();
                    Cursor cursor = db.query("user_name", new String[]{"count(*) ID"}, null, null, null, null, null);
                    while(cursor.moveToNext())
                    {
                        int idFromDatabase = cursor.getInt(cursor.getColumnIndex("ID"));
                        if(idFromDatabase != 0)
                        {
                            id = 1 + idFromDatabase;
                        }
                    }
                    ContentValues values = new ContentValues();
                    values.put("ID", id);
                    values.put("name", nameEditText.getText().toString().trim());

                    flag = db.insert("user_name", null, values);
                    if(flag != -1)
                    {
                        Toast toast = Toast.makeText(Entername.this, "You have successful inserted this record into database! ", Toast.LENGTH_LONG); 
                        toast.show();
                        db.close();

                        //clear fields              //clearing edittexts
                           nameEditText.setText("");

                        return;
                    }
                    else
                    {
                        Toast toast = Toast.makeText(Entername.this, "An error occured when insert this record into database!", Toast.LENGTH_LONG); 
                        toast.show();
                        db.close();

                        //clear fields
                        //clearing edittexts
                           nameEditText.setText("");
                        return;
                    }
                }
            }

            public void onClick(DialogInterface dialog, int which) 
            {
                // TODO Auto-generated method stub
            }
        }

        class DoneButtonListener implements OnClickListener, android.view.View.OnClickListener
        {
            public void onClick(View v) 
            {   
                Intent myIntent = new Intent(v.getContext(), Pickholespubs.class);
                 startActivityForResult(myIntent, 0);
            }

            public void onClick(DialogInterface dialog, int which) 
            {
                // TODO Auto-generated method stub  
            }
        }

        class showButtonListener implements OnClickListener, android.view.View.OnClickListener
        {
            public void onClick(View v) 
            {
                String display = "";
                SQLiteDatabase db = dbHelper.getWritableDatabase();
                /** the result will be loaded in cursor **/
                Cursor cursor = db.query("user_name", new String[]{"ID","name"}, null, null, null, null, null);
                /** check if the table is empty **/
                if (!cursor.moveToNext())
                {
                    addTextView.setText("No data to display, please make sure you have already inserted data!");
                    db.close();
                    return;
                }
                cursor.moveToPrevious();
                /** if the table is not empty, read the result into a string named display **/
                while(cursor.moveToNext())
                {
                    int ID = cursor.getInt(cursor.getColumnIndex("ID"));
                    String name = cursor.getString(cursor.getColumnIndex("name"));

                    display = display + "\n"+"Player"+ID+", Name: "+name;
                }
                /** display the result on the phone **/
                addTextView.setText(display);
                db.close();
            }

            public void onClick(DialogInterface dialog, int which) 
            {
                // TODO Auto-generated method stub  
            }
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:45:28+00:00Added an answer on June 1, 2026 at 9:45 pm

    Try like this,

    @Override
        public void onCreate(SQLiteDatabase db) {
            String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_DETAILS + "("
                    + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT," 
                    + KEY_NUMBER + " TEXT,"  + KEY_MAIL + " TEXT" + ")";
            db.execSQL(CREATE_CONTACTS_TABLE);
            String CREATE_ONLINE_TABLE = "CREATE TABLE " + TABLE_ONLINE_DETAILS + "("
                    + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
                    + KEY_MAIL + " TEXT,"  + KEY_PHONE + " TEXT"+ ")";
            db.execSQL(CREATE_ONLINE_TABLE);
    
        }
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_DETAILS);
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_ONLINE_DETAILS);
            onCreate(db);
            }
    

    you can call the method in your java class like

    db.add(String, String, String);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge table from one mysql db, I want to create a
I have created one table using the below command: create table Table1( Id int
I have to create one table using XSLT and CSS. The table should look
I have created one aspx Page from that i need to access the property
I have created one user named tuser with create database rights in SQL server
I have created one dynamic button in my application and I call the following
i have created one table view in which i have provided searching & deleting
I have a users table, the user ID is public. But I want to
In the first time I have created one Table DEPTS . After that I
Ok, I have one JavaScript that creates rows in a table like this: function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.