Android SQLite Database Tutorial 3 # Insert values to SQLite Database table using Android

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 275

  • @HabiburRahman-xs9gb
    @HabiburRahman-xs9gb 4 года назад +2

    2015/2016 In my university for the OOP course I had to build a project and this channel helped me the most. that time ProgrammingKnowledge had 2lakhs subscribers....now it's more than a million...5 years with this channel as a subscriber...I always find your tutorials the best, easy to understand, no bullshit or unnecessary explanation..and you talk slow...that's a huge help for slow learners like me. please keep making tutorials like this. I'm now studying in a German University..came from Bangladesh. Hope to build a career in Programming but this channel will always be the part of my success.

  • @christianmichon1940
    @christianmichon1940 8 лет назад +6

    Just to let you know that i've created my first android application thanks to your videos. So thank you for this tutorial which is very well done !!!!!

  • @luxpraja9727
    @luxpraja9727 7 лет назад

    I am a beginner learning android and i found this tutorial helpful

  • @duncanfirth
    @duncanfirth 6 лет назад +1

    You Rock this video really saved me, I am studying Android and was confused by the Database section Thank you!

  • @michaelvandi1
    @michaelvandi1 7 лет назад

    Great tutorials, we like the way you elaborate on what every single code does in simple English

  • @jfrancoginn6923
    @jfrancoginn6923 8 лет назад +5

    DUDE THIS THING WORKED LIKE A CHARM!

  • @madinafazli8394
    @madinafazli8394 3 года назад

    Your explanation is some other level!
    Thanks

  • @kattejansp2980
    @kattejansp2980 9 лет назад

    For Mac instead of ctrl+click use cmd+down arrow to go to the class and see it in its context. or ctrl+j for documentation.

  • @BookFans-co-uk
    @BookFans-co-uk 4 года назад

    Nice example. However when adding data to SQLite database, as soon as data is added you can reset the UI texts to blank.

  • @MazenItani
    @MazenItani 8 лет назад +3

    Finally:
    your code is perfect, BUT the extended class ActionBarActivity were recently deprecated.
    ActionBarActivity is deprecated; use `AppCompatActivity` instead
    Thanks

  • @Ahmed-wj5sd
    @Ahmed-wj5sd 8 лет назад +33

    if (isinserted = true) // is always true because you force it
    replace = by ==

    • @drtan2053
      @drtan2053 7 лет назад +3

      nope , still didnt work

    • @jakemacale9735
      @jakemacale9735 7 лет назад +7

      or you can simply type
      if(isInserted) {} //for true
      if(!isInserted} {} //for false

    • @janduchac2307
      @janduchac2307 6 лет назад +1

      boolean == true; facepalm

    • @RengarThePredator
      @RengarThePredator 5 лет назад

      Actually he's passing string to database helper constrictor, pass int, it should work

    • @praveenfernando
      @praveenfernando 5 лет назад

      @@jakemacale9735 not working

  • @muhamadhaydar8419
    @muhamadhaydar8419 5 лет назад +1

    Great tutorial!
    I guess to run it on your device! Not emulator.
    I spent half an hour testing it on the emulator.
    but it's always showed me "data not inserted", still, I don't know what's going on in emulator.
    but then I run the same code on my device it worked properly.

    • @anaibrahim4361
      @anaibrahim4361 5 лет назад

      i spent the whole day repeating the code to check why it doesn't work for me until i found this comment shiiiiiit i don't know how to thank you,

    • @xx-wp3mq
      @xx-wp3mq 5 лет назад

      Odd mine worked on an emulator (Pixel 2)

  • @2010apap2010
    @2010apap2010 8 лет назад

    Nice tutorial with little mistakes, actually one is a big one.
    First you should start method names with lower case letters.
    And then the big thing is, you check if data is inserted by an if clause. But in the if condition, you set your boolean variable to true, which means that it will always say Data Inserted.
    If you want to compare values, you need 2 equals, so it has to be isInserted == true. BUT you never compare booleans like that. you just type if(isInserted) {...}, if you want to run the following code when your variable is true and if(!isInserted){...} if its false.

  • @ganeshkumar4954
    @ganeshkumar4954 8 лет назад +3

    Hi, The database created fine. but when I insert the data for the first time, the data inserted. while populating the records , i'm not able find the data which was inserted first.

  • @Top10Reveals
    @Top10Reveals 5 лет назад

    Very nice teaching method, God bless you.

  • @NoName-pz7mk
    @NoName-pz7mk 5 лет назад

    instead of using an if statement ; you can use ; return result != -1 and if(inserted==true) isnt necessary , replace it buy if(inserted)

  • @princeheir1347
    @princeheir1347 8 лет назад

    You are Awesome i had problems before with android database and now they are all solved :):):):)

  • @tianjinzhou1329
    @tianjinzhou1329 8 лет назад +3

    2 questions:
    1) isn't MARKS integer type in previous video ?
    2)" if ( isInserted = true ) " should be " if ( isInserted == true ) " or " if ( isInserted) " ?
    Regards

    • @NoName-pz7mk
      @NoName-pz7mk 5 лет назад

      if ( isInserted == true ) and if ( isInserted) are both correct

  • @anirudhkaranam414
    @anirudhkaranam414 7 лет назад +3

    Despite doing exactly what has been done in the tutorial, every time I press the add button, I get a "data not inserted" message. How do I fix this?

    • @androidpower1993
      @androidpower1993 4 года назад +1

      Just clear the app data and reinstall the app.

  • @RaedZein
    @RaedZein 9 лет назад +3

    I don't think you've noticed but your if condition in the end basically changes any result coming from the isInserted function to true, because its boolean, you should phrase the condition to (isInserted) rather than be (isInserted=true), that really checks if its true or false, which it never is, please revise your tutorials

    • @sahidul154
      @sahidul154 7 лет назад

      exactly, that's why he didn't show at the end how he inserted the data

  • @amithajerard1321
    @amithajerard1321 5 лет назад +2

    Thanks a lot for this series, it helped me out a lot

  • @raksanafazil5153
    @raksanafazil5153 4 года назад

    It's very helpful but how to insert multiple tables in one database ....I request you to say how to insert multiple tables in Database

  • @turboromy
    @turboromy 8 лет назад

    Thanks for the through and detailed video. I got one burning question. How do you work with float, long, double data type from Java to SQL ? SQL only seem to have REAL and I wasn't able to solve this puzzle yet.

  • @sitararafaqat
    @sitararafaqat 3 года назад

    Thanks alot for this easiest tutorial ,it helped me alottttttttt

  • @lysentertainment4676
    @lysentertainment4676 4 года назад

    Awesome training..carry on guru

  • @marcoribeiro1795
    @marcoribeiro1795 5 лет назад

    Hello, very nice videos, helping me a lot, thanks!
    I would like to ask you, We can do that with a scanner code bars, I mean, send the code to the database and after that show on the screen in a list ? Do you where I can find the code for that?

  • @kevinrea7820
    @kevinrea7820 Год назад

    the program runs now without any errors, but, when i insert data into the database, it says Data Inserted, but, when i go and check the contents of the database, there are no records inside the database. I ran the program several times and inserted a different record each time, but still, no data in the .db database when i open to check it..

  • @chanchalkishore
    @chanchalkishore 8 лет назад +2

    Can this same coding be run in eclips?
    If yes - then it is showing "Force Close". While i run this app.

  • @satyamshashankkaran5886
    @satyamshashankkaran5886 4 года назад

    For same method, My app keeps on crashing suddenly. The error found in logcat was
    "NullPointerException: attempt to invoke virtual method Boolean on null reference object in method AddData....." And the indicated line is "Boolean insertData = myDB.addData(newEntry);"
    I tried to handle with try catch but it always comes up in block whenever I hit add button in the app..
    Please help.

  • @ajsantiaguel3415
    @ajsantiaguel3415 7 лет назад +1

    db.execSQL("create table " + TABLE_NAME +" (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,SURNAME TEXT,MARKS INTEGER)");
    change to:
    db.execSQL("create table " + TABLE_NAME +" (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,NAME STRING,SURNAME STRING,MARKS INTEGER)");
    MY ERROR STOPPED

  • @smarttechaakash7324
    @smarttechaakash7324 4 года назад

    Sir when I creating database it's working in android version 4.4 but it's not working 9 pie why.
    When I insert the data into table inserted successfully in 9 pie version .
    But when I checke the data in android monitor it's only showing database name nothing else..
    Inside the database name no any column is showing .
    But the similar application working with android version 4.4 ..
    Please make the videos on this problem.

  • @lelaventurier8477
    @lelaventurier8477 8 лет назад +2

    Thanks for this Tutorial, It helped me to Create Highscore Table in my game :)

  • @ralfschmitt1848
    @ralfschmitt1848 4 года назад

    Great video ! I have one strange issue, when I add a new entry it gets created twice. The table contains two different ID's with the same data. Any idea ?

  • @bharanisundar5272
    @bharanisundar5272 8 лет назад

    Nice tutorial, but how to fetch the data in separate page instead of dialogue? Please help me.. Thank you.

  • @TheMashmeister
    @TheMashmeister 6 лет назад

    you can just try/catch to see if the values are inserted, that would be much better

  • @ujwalaujju7885
    @ujwalaujju7885 6 лет назад +3

    app unfortunately stopped
    in Android sdk version 3.0.1

  • @bitaazarijoo1135
    @bitaazarijoo1135 7 лет назад

    Hi. I followed all your instructions and while executing the app, I can't run it completely bc when executing this.getWritableDatabase() the app stops & I can't figure out why? What should I do ?
    Thanks

  • @narendersinghraman4529
    @narendersinghraman4529 8 лет назад +1

    brillliant tutorial sir........thanks for helping.........!!!!!!

  • @MrAbish1
    @MrAbish1 4 года назад

    I tried using the exact same code and it's not showing the inserted data in DB Browser for SQLite is anything I want to deal with the emulator? i am using USB debugging to run my application

  • @aliagha00
    @aliagha00 9 лет назад

    Thanks man, very easy to follow, great tutorials.

  • @sadaalrough6996
    @sadaalrough6996 4 года назад

    in case I have more than 4 or five tables, how I will write data in the public boolean insertData() method?

  • @elayas9026
    @elayas9026 6 лет назад

    I just want to say about this video.awesome!!!!

  • @aliagha00
    @aliagha00 9 лет назад

    i wish you could do some tutorials using web-services to extract data from Mysql server.
    i tried quite a few of the available android tutorials on RUclips, None came close to what you are doing.

  • @יהונתןפרידמן-ב7ק
    @יהונתןפרידמן-ב7ק 9 лет назад +2

    thank you! I really like your tutorials. You are the best!

  • @xodemifan1xo
    @xodemifan1xo 9 лет назад +1

    can i add through the sqlite manager/db browser for sqlite itself because my most inportant thing is to retrieve first then insertion comes later..

  • @jaydeepbhoite5829
    @jaydeepbhoite5829 5 лет назад

    I already have a databse of what i want to add. I do not want to follow the insert procedure , how can i directly give my data to the table and display it ?

  • @education_beauty
    @education_beauty 3 года назад

    Sir I have a question
    If I get number from user in sign up activity then how can I use that number in home activity plz tell me

  • @motasemha3404
    @motasemha3404 9 лет назад

    Hi
    its realy great thank you .
    I would like to ask you if its possible to use the same steps at eclipse application or we should do that just on android stodio
    thanks

  • @elliotalderson3596
    @elliotalderson3596 8 лет назад +5

    your if condition at the onClickListener method is wrong use this instead if ( isInserted == true ){}

  • @musicTvChannel2024
    @musicTvChannel2024 7 лет назад

    I dOn't get it. Why is that your program still running even the Condition of if else statement in 11:25 is Set a value not equal to? Can you please explain it to me?

  • @sanjaykumarbarfa1810
    @sanjaykumarbarfa1810 9 лет назад +1

    hi can u tell me how to validate user credential here i want do when click AddData button before validate like name surname etc..
    boolean isInserted = myDb.insertData(editTextName.getText().toString(),
    editTextSurname.getText().toString(),
    editTextMarks.getText().toString())

  • @DrSatti
    @DrSatti 7 лет назад

    If he made errors, how his program is running. Seems fishy. I have error
    Error:(46, 39) error: is not abstract and does not override abstract method onClick(View) in OnClickListener.
    Any idea?

  • @beautifulgirlmage
    @beautifulgirlmage 8 лет назад

    If you guys are having problem with crashing down then this is the right comment to help you:
    db.execSQL("Create Table " + TABLE_NAME + "(B_id INTEGER PRIMARY KEY AUTOINCREMENT, B_title TEXT, B_author TEXT)");
    In the line above you could have probably missed the extra Closing parenthesis. Hope this helps you guys, keep programming :)

  • @parchana20
    @parchana20 7 лет назад

    Very well explained, great work! Keep it up!

  • @samCoder
    @samCoder 7 лет назад

    PLEASE HELP
    When I click the button it says Data not inserted but I have the same code as video. I don't know what to do helpp!

  • @entlemmipi2621
    @entlemmipi2621 7 лет назад

    Hi, in my DatabaseHelper.java I am getting a red squiggly line under the "put" method with the error message "non static method put cannot be referenced from a static context". How do I fix this? Thanks.

  • @petercannon1865
    @petercannon1865 6 лет назад

    Great tutorial insertion success could have been ascertained using
    return value == -1;
    Rather than using an if statement

  • @soham.patel95
    @soham.patel95 8 лет назад

    Nice Work...it helped me a lot...Thanks for sharing...

  • @Suraj-tz3oq
    @Suraj-tz3oq 5 лет назад +1

    11:25 I think there is a typo-> "isInserted==true" is correct

  • @angelren4563
    @angelren4563 8 лет назад

    How do you put DATE and TIME in database? assmue to have DueDate as Col name and type is DATETIME, how will you gonna concatenate the date and time? by using textview wriiten in date (passed the value from the other) then concatenate the timepicker dialog chosen value?

  • @omaisakhtar2433
    @omaisakhtar2433 4 года назад

    make on video on how to insert image into sqlite database and retreive image from database in android studio

  • @javadkv
    @javadkv 7 лет назад

    I am a beginner
    just after running the project, when I checked database data folder in device monitor it contains nothing.
    Also when you created below coding? and is it necessary for just creating the table on db?.
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main,menu);
    return true;
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    return true;
    i am getting error on R.menu line

  • @samii5205
    @samii5205 7 лет назад

    thinks sir g very helpful territorial ......very impressive

  • @heavenaldrico
    @heavenaldrico 5 лет назад +3

    I got Data not Inserted instead, and my database's table is empty. So it failed to insert the data right? Anyone know how to fix it?

    • @yedukrishnan5862
      @yedukrishnan5862 4 года назад

      Me too.. please explain anyone??

    • @heavenaldrico
      @heavenaldrico 4 года назад +1

      @@yedukrishnan5862 i got it fixed but i dont remember what it is. I think you should check your code again.

  • @mmmmm805
    @mmmmm805 7 лет назад +3

    when I press the Add Data button the negative toast appear informing me that it's failed to be inserted in the database, I also checked the database manager and i found the table empty. I'm sure I did all the instructions properly. can anyone help me to find the where's the error and what's the solution??

    • @dreamerson
      @dreamerson 7 лет назад

      same problem

    • @sanderhuisman9238
      @sanderhuisman9238 6 лет назад

      Did you find the solution on this error. I get the same here... :-(

    • @devarora3770
      @devarora3770 6 лет назад

      try adding permission in manifest file of read/write..!!

  • @bereshyitbara7586
    @bereshyitbara7586 8 лет назад

    Hi Guys! In My AS 2.2.1, under layout folder there are two .xml files: activity_main.xml (where such a statement “” is written) and content_main.xml. Which of the two is correct to have the source codes here been written? I'm informed that activity_main.xml is better because it is the layout for the MainActivity. Thank you all in advance.

  • @benzciocon3636
    @benzciocon3636 6 лет назад

    why is that only ID column appears in the Sqlite no name and marks even though i review your code. no data stored in my sqlite reply asap thanks

  • @aong295
    @aong295 7 лет назад

    very nice, easy to learn, big thanks !

  • @16pxdesign
    @16pxdesign 7 лет назад

    how is it works in some app for example there is something like local DB and if you connect to internet it make something like update to main DB and update your local for next offline use? Whats that solution ?:P i cant imagine this

  • @harshitagothwal7855
    @harshitagothwal7855 9 лет назад

    i want to add a "show" button..such tht on clicking tht button full database table will get displayed on screen..what should i do for this..how do i display table..?? can u plz explain..

  • @yaseefsheikh5925
    @yaseefsheikh5925 6 лет назад

    what if i dont want duplicate values in my database and it should show an error if done so and i only have one column "name" in my db which is declared as unique, what should i do? please help and
    thank you

  • @dhruv04
    @dhruv04 8 лет назад

    Please tell me how can I validate the data before insertion as it's executing insert query even if there is no data in EditTexts ? Thanks for sharing this tutorial it's excellent..

    • @Clos111888
      @Clos111888 8 лет назад

      +dhruv sahni Yeah thats one thing he didnt explain but Im sure there are videos on that

  • @roul3688
    @roul3688 6 лет назад +1

    What if the database already exists on the device? Does you DatabaseHelper constructor overwrite/replace the existing database with a new one or will it just pull what's already existing?

    • @idksoiputthis2332
      @idksoiputthis2332 6 лет назад

      there is a sql keyword called "exists" and can be used in if statement (in SQL not java) to detect if the data base exists or not, and can delete and recreate the database based on that. Research that keyword for more info

  • @DrSatti
    @DrSatti 7 лет назад +2

    i found the answer
    @Override
    public void onClick(View view) {
    }

  • @louismori3379
    @louismori3379 8 лет назад

    thank you for this tutorial, exactly what I was looking for

  • @josephjoey3904
    @josephjoey3904 8 лет назад

    I used the same code and followed the same procedures, but the table is still not created. How can I create it?

  • @Seankim-vj1fl
    @Seankim-vj1fl 6 лет назад

    very useful i can grab the flow of it

  • @appsolstechnologies8356
    @appsolstechnologies8356 9 лет назад

    when i click on add date "Unfortunetely app is stopped" msg is displayed...can u please help where i do mistake

  • @powderpofgirls
    @powderpofgirls 8 лет назад

    how do i do it for a spinner, iv created the spinner but i just want the options only from the spinner to go into my database

  • @kajb34
    @kajb34 9 лет назад

    This is all very clear. Thank you.

  • @BeginnerTopro
    @BeginnerTopro 7 лет назад

    in my case data were being added at the first time only then it's not inserting data why??

  • @vickynegi1345
    @vickynegi1345 5 лет назад

    That extension is bugged, it didn't show any data but i checked database on inloop.github.io/sqlite-viewer/
    it showed the data saved
    also i changed the version in super method from 1 to 2

  • @johnnugent3992
    @johnnugent3992 4 года назад

    I was liking the tutorial BUT the main activity is created as an extension of a defunct class which ruined my experience

  • @MATholic324
    @MATholic324 9 лет назад +5

    when i click on add date "Unfortunetely app is stopped" msg i received...plz help

    • @arifinfirdaus7379
      @arifinfirdaus7379 9 лет назад

      +Mithilesh Bhalekar me too!!

    • @MATholic324
      @MATholic324 9 лет назад

      +Xudong Ran hello...i got solution for this error...plz chk whether you hav typed create table's properly or not ?? thats the main issue I hd to resolve

    • @MATholic324
      @MATholic324 9 лет назад +2

      +Arifin Firdaus db.execSQL("create table " + TABLE_NAME +" (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,SURNAME TEXT,MARKS INTEGER)");
      chk whether u hav entered dis properly or not ?

    • @arifinfirdaus7379
      @arifinfirdaus7379 9 лет назад

      +Mithilesh Bhalekar my bad. I've changed MARKS TEXT to MARKS INTEGER now. Thankyou Mithilesh Bhalekar

    • @MATholic324
      @MATholic324 9 лет назад

      +Arifin Firdaus 👍👍👍

  • @shubhamsoni972
    @shubhamsoni972 7 лет назад

    Hello sir, i m not able to see the package for check to see wheather the connection is created or not how to di it i need help?

  • @nyla6991
    @nyla6991 8 лет назад

    anyone know a good video where you store EXISTING CONTACTS into a SQLite db? all of the videos i find are storing user "strings" into the db.
    I want to be able to pull the existing phone book including name / number & store into my own db.

  • @rushabhm2367
    @rushabhm2367 7 лет назад

    if i keep adding numbers one after another , will it create multiple rows?

  • @_akbarnugraha
    @_akbarnugraha 7 лет назад

    how to show automatically column ID (auto increment) into Edit Text when you input the data at the same time ?

  • @gorcsaandreea2735
    @gorcsaandreea2735 5 лет назад

    Thank you! It was very useful. Gob bless you!

  • @jeremyyochum9033
    @jeremyyochum9033 6 лет назад

    How do you access a string passed to a TextView to log to the database?

  • @Gardeningwithmayu
    @Gardeningwithmayu 7 лет назад

    public void onCreate(SQLiteDatabase db) {
    db.execSQL("create table " + TABLE_CONTACTS +" (id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT,surname TEXT,marks INTEGER)");
    }
    i use this code .my application is not work properly(unfortunately app is stopped)
    can anyone please give the proper solution?

  • @johnjackson8710
    @johnjackson8710 6 лет назад

    Sir how can i use SQLiteOpenHelper object out of MainActivity?

  • @xidigalove
    @xidigalove 8 лет назад

    Thanks man Its working. thumps up.

  • @prachikhetwal2196
    @prachikhetwal2196 6 лет назад

    mainactivity.java is showing action_setting in red even after alt+enter no improvement
    if (id == R.id.action_settings) {
    return true;
    }
    return super.onOptionsItemSelected(item);
    }

  • @damia4579
    @damia4579 4 года назад

    how to add the datepicker and radiobutton in the same database ?

  • @Aristodemos24
    @Aristodemos24 8 лет назад

    Fantastic tutorials, thank you

  • @アリアガダビッドクリス
    @アリアガダビッドクリス 8 лет назад +4

    u made a mistake in the last if
    it should be == not =

    • @sahidul154
      @sahidul154 7 лет назад

      ya this video is a waste, he never showed at the end that he was able to insert data

  • @jkuhede
    @jkuhede 6 лет назад

    How do you change the text and ID's of the views like that ?

  • @kalidamn3544
    @kalidamn3544 5 лет назад

    I get -1 result by which it return false. Please tell me how I fix it?

  • @aeronjohngarcia
    @aeronjohngarcia 7 лет назад

    Can I run that in my phone? Coz my emulator is getting lag and hang