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 9291473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:39:20+00:00 2026-06-18T20:39:20+00:00

Please have a look at the following code Code to insert data package com.example.esoftcallmanager;

  • 0

Please have a look at the following code

Code to insert data

package com.example.esoftcallmanager;

import android.app.Activity;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;

public class DatabaseHandler implements DatabaseConnector
{
    private SQLiteDatabase database;
    private String dbPath = "data//data//com.example.esoftcallmanager.sqllite//esoftDatabase";
    private static Context context;

    private static DatabaseHandler instance;

    private DatabaseHandler(Context context)
    {
        this.context = context;
    }

    @Override
    public void createConnection() 
    {

        try
        {
            database = context.openOrCreateDatabase("esoftDatabase", Context.MODE_PRIVATE, null);

            String createDatabaseQuery = "create table BranchNetwork(" +
                    "brID integer primary key autoincrement,"
                    +"city text,"
                    +"streetAddress text,"
                    +"phoneNumber1 text,"
                    +"phoneNumber2 text,"
                    +"email text"
                    +");";

            String dropDatabaseQuery = "drop table BranchNetwork";
            database.execSQL(createDatabaseQuery);


        }
        catch(SQLException sql)
        {
            Toast.makeText(context, sql.getMessage(), Toast.LENGTH_LONG).show();
        }

    }

    @Override
    public void closeConnection() {
        // TODO Auto-generated method stub

    }

    @Override
    public String getPhoneNumber() {
        // TODO Auto-generated method stub
        return null;
    }

    public static DatabaseHandler getInstance(Context context)
    {
        if(instance==null)
        {
            instance = new DatabaseHandler(context);
        }

        return instance;
    }

    public static DatabaseHandler getInstance()
    {
        if(instance==null)
        {
            instance = new DatabaseHandler(context);
        }

        return instance;
    }

    @Override
    public String insertData(String city, String streetAddress,String phoneNumber1, String phoneNumber2, String email) 
    {
        String insertQuery = "insert into BranchNetwork ('city','streetAddress','phoneNumber1','phoneNumber2','email') values("+city+","+streetAddress+","+phoneNumber1+","+phoneNumber2+","+email+");";

        try
        {
            database.execSQL(insertQuery);
            return "Data Successfully Inserted";
        }
        catch(Exception e)
        {
            Toast.makeText(context, "Exception: "+e.getMessage(), Toast.LENGTH_LONG).show();
            return "Data Insertion Failed";
        }

    }


}

Whenever I try to insert data, I get the following error

   02-13 23:39:40.424: E/Database(655): Failure 1 (near "@wewe": syntax error) on 0x2a6128 when preparing 'insert into BranchNetwork ('city','streetAddress','phoneNumber1','phoneNumber2','email') values(asas,asasd,3434,3434,aasa@wewe.com);'.

What is wrong here? How can I correct it? Please help!

  • 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-18T20:39:21+00:00Added an answer on June 18, 2026 at 8:39 pm

    Quite simply, you need to wrap your Strings in quotes.

    "values('"+city+"','"+streetAddress+"'..."
    

    However, it is often better to use a parameterized query when working with raw values to prevent SQL injection attacks and other unsavory things:

    db.rawQuery("insert into Foo (bar) values (?)", new String[] {city});
    

    Or use the built-in methods like SQLiteDatabase#insert()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please have a look at the following code package Euler; import java.util.ArrayList; import java.util.List;
Please have a look at the following code <RelativeLayout 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:descendantFocusability=afterDescendants
Please have a look at the following code <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
Please have a look at the following code activity_main.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
Please have a look at the following code <ScrollView 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 tools:context=.DisplayResult
Please have a look at the following code. package normal; import java.awt.*; import java.awt.event.*;
Please have a look at the following code package email; import java.awt.*; import java.awt.event.*;
Please have a look at the following code <ScrollView 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 tools:context=.Form
Please have a look at the following code <ScrollView 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 tools:context=.Form
Please have a look at the following code package normal; import java.io.*; import java.util.*;

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.