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

  • Home
  • SEARCH
  • 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 7729023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:51:51+00:00 2026-06-01T05:51:51+00:00

Code for SQL class as follows: import java.text.SimpleDateFormat; import java.util.Date; import android.content.ContentValues; import android.content.Context;

  • 0

Code for SQL class as follows:

import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.ContentValues;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class sqlDatabase {

public static final String KEY_ROWID = "_id";
public static final String KEY_PURCHASEREFUND = "_purchaserefund";  
public static final String KEY_LOCATION = "_location";
public static final String KEY_SHOPTYPE = "_shoptype";
public static final String KEY_PRICE = "_price";
public static final String KEY_DATE = "_date";
public static final String KEY_CARDUSED = "_cardused";

private static final String DATABASE_NAME = "receiptdb";
private static final String DATABASE_TABLE = "receipttable";
private static final int DATABASE_VERSION = 1;  

private receiptDBhelper receiptHelper;
private final Context receiptContext;
private SQLiteDatabase receiptDatabase;


private static class receiptDBhelper extends SQLiteOpenHelper{

    public receiptDBhelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }       

    @Override
    public void onCreate(SQLiteDatabase rdb) {
        // TODO Auto-generated method stub
        rdb.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
                KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                KEY_DATE + " TEXT NOT NULL, " +
                KEY_CARDUSED + " TEXT NOT NULL, " +
                KEY_LOCATION + " TEXT NOT NULL, " +
                KEY_SHOPTYPE + " TEXT NOT NULL, " +
                KEY_PRICE + " TEXT NOT NULL);"          
        );
    }

    @Override
    public void onUpgrade(SQLiteDatabase rdb, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        rdb.execSQL("DROP_TABLE_IF_EXISTS " + DATABASE_TABLE);
        onCreate(rdb);
    }

}

public sqlDatabase(Context c){
    receiptContext = c;
}

public sqlDatabase open() throws SQLException {
    receiptHelper = new receiptDBhelper(receiptContext);
    receiptDatabase = receiptHelper.getWritableDatabase();
    return this;        
}

public void close(){
    receiptHelper.close();
}

public long createEntry(String purchaserefund, String shoptype,
        String location, String price, String cardused) {
    // TODO Auto-generated method stub

    ContentValues dbcv = new ContentValues();

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
    Date date = new Date();

    dbcv.put(KEY_PURCHASEREFUND, purchaserefund);
    dbcv.put(KEY_SHOPTYPE, shoptype);
    dbcv.put(KEY_LOCATION, location);
    dbcv.put(KEY_PRICE, price);
    dbcv.put(KEY_CARDUSED, cardused);
    dbcv.put(KEY_DATE, dateFormat.format(date));        

    return receiptDatabase.insert(DATABASE_TABLE, null, dbcv);
}

}

Relevant code for class that uses the SQL class:

String purchaserefund = precspurchaserefunds;
String shoptype = precsshoptypes;
String location = precsshoptypesselection[precsshoptypeselection];
String price = precsprices;
String cardused = precscarddetails[precscardusedselection];

sqlDatabase entry = new sqlDatabase(precs.this);

entry.open();

entry.createEntry(purchaserefund, shoptype, location, price, cardused);

entry.close();

As far as I’m aware, all the code is there and is correct, but for some reason when I look into an SQL Database Browser, there are no values inserted?

  • 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-01T05:51:53+00:00Added an answer on June 1, 2026 at 5:51 am

    I think the problem is actually how you are checking the sql db content. Usually the db file is stored under /data/package_name/databases (or something like that, I don’t remember the exact path), and without root access you cannot just read files inside that folder.

    So with a SQL Database Browser that’s probably the issue..

    Try to access your data through your app and see if the data is there. Also, keep an eye on LogCat, there might be some warnings/errors related to the Db.

    (PS. there’s no need to call “commit”…)

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

Sidebar

Related Questions

The following is my Class code import java.net.*; import java.util.*; import java.sql.*; import org.apache.log4j.*;
The classic way to query an SQL database case-insensitively from Java is as follows:
I have the following SQL code that runs against a Change Request database. Each
I have two models in Django like follows(in pseudo code) class Medicine(db.Model): field_1 =
I try to execute raw SQL in Grails with this code: class PlainSqlService {
I have a stored proc mapped as follows in NHibernate: <sql-query name=HistoricSearch> <return class=ResultItem>
code: sql.php <?php $uid = trim($_POST['uid']); $pass= trim($_POST['pass']); $type= trim($_POST['type']); $link = mysql_connect(localhost,root,akash); if
My code for sql connection using linq is: var query1 = from u in
This SQL Server 2005 T-SQL code: DECLARE @Test1 varchar; SET @Test1 = 'dog'; DECLARE
I've written PL/SQL code to denormalize a table into a much-easer-to-query form. The code

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.