3. How to Insert Data into Database using PreparedStatement in JDBC.

Sdílet
Vložit
  • čas přidán 25. 02. 2021
  • Let's understand, How to insert data [Entered by the User] into database using JDBC and PreparedStatement in java. In this session, we will see how to use PreparedStatement interface in JDBC and how to set dynamic data to PreparedStatement insert query.
    In this session, I have discussed following points.
    1. What is prepared statement in JDBCin java?
    2. How to insert values into table using JDBC and PreparedStatement?
    3. How to set dynamic values to PreparedStatement query which are entered by the user?
    Disclaimer - The music/audio used(if any) in this video is not a property of "Learn Programming Yourself". All credit goes to owners of respective music/audio. This music/audio is not prone to any "Copyright Strikes".
    --------- Links to my other FREE courses. ---------
    ▶ Java 8 Full Course - • Java 8
    ▶ JDBC Full Course - • 1. Introduction to JDB...
    ▶ Microsoft Cognitive Services Course - • Computer Vision + Angu...
    ▶ JWT in Spring Boot and Angular - • How to download and in...
    ▶ CRUD Operations in Spring Boot and Angular (Full Stack) - • 1. Angular 16 and Spri...
    ▶ Console Based Banking Application Using Java - • Developing Console Bas...
    ▶ E-Commerce Application Development Using Angular and Spring Boot (Full Stack) - • 1. Developing E-Commer...

Komentáře • 160

  • @THE_VIKRAM_VISION...4.O
    @THE_VIKRAM_VISION...4.O Před rokem +2

    Successfully inserted Values into the table!
    Thank you! so much sir!

  • @kiransutar5257
    @kiransutar5257 Před 2 lety +1

    Very Nicely Explained ......
    एकदम भारी 👍👍

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před 2 lety

      थँक्स भावा व्हिडिओ बघितल्या बदद्ल. मराठी मधून कंमेन्ट बघून एकदम भारी वाटल बघ

  • @rishadrio9676
    @rishadrio9676 Před rokem +2

    You explained well and easy to understand the concept...

  • @FireNoon50829
    @FireNoon50829 Před 11 měsíci +3

    Great explanation good job.

  • @user-uk2sz5br7w
    @user-uk2sz5br7w Před rokem +2

    Thank you for the excellent explanation.

  • @sriganeshreddynallamilli6687

    You really explained very well bro... Thanks for your Support...🤝🤝

  • @dayanandswami8109
    @dayanandswami8109 Před 2 lety +1

    Dear Sir,
    I Thank you for your valuable guidance.
    Thanks a lot

  • @THE_VIKRAM_VISION...4.O
    @THE_VIKRAM_VISION...4.O Před rokem +1

    Thank you! Very Much Sir!, Such a wonderful Explanation

  • @SAUMILPatel2
    @SAUMILPatel2 Před 3 lety

    Awesome explanation !!

  • @vishwak2091
    @vishwak2091 Před rokem +1

    Very nice thanku sir🙏🙏

  • @atharv1312
    @atharv1312 Před 3 lety +1

    Outstanding

  • @nikhil5062
    @nikhil5062 Před 3 lety +1

    Thankyou bhaiya ..❤️❤️

  • @UjjwalKumar-tv5ms
    @UjjwalKumar-tv5ms Před rokem +2

    bhaiya could you please help me.. i am getting error : - Exception in thread "main" java.lang.RuntimeException: Something went wrong
    at com.jdbc.student.StudentDatabase.main(StudentDatabase.java:36)
    my database name is correct , everything is done according to your concept.. then why this errors are coming. please help asap. thanks

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před rokem +1

      I need to take a look to code in order to help you

    • @UjjwalKumar-tv5ms
      @UjjwalKumar-tv5ms Před rokem +1

      @@LearnProgrammingYourself Thanks bhaiya..but the problem got resolved... Actually i was giving wrong password that's why i faced this issue. But anyway..your course was too much helpful. Thanks.

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před rokem +1

      Ohh great

  • @shravangoudbangla1862
    @shravangoudbangla1862 Před rokem +1

    ❤❤

  • @harshitapilodiya8301
    @harshitapilodiya8301 Před 5 měsíci

    I have error in private static Connection connection=null;

  • @ishikajain1556
    @ishikajain1556 Před rokem +1

    Sir, you explained very well but eclipse is not allowing me to add external jar files, I followed exact steps as you said, please help!

  • @lucky-2024
    @lucky-2024 Před 6 měsíci

    Instead of only raj how can we add multiple names, percentage address...at a time?

  • @kmonika4718
    @kmonika4718 Před 2 lety +1

    where will we get the driver name that you have added in the start?

  • @harshojha2292
    @harshojha2292 Před 10 měsíci +1

    mere me to java.lang.null pointer exception how to resolve that

  • @Abhi-mz8xd
    @Abhi-mz8xd Před 2 lety +1

    why to add IntegerparseInt when we are entering direct Integer datatype??

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před rokem

      Yes your question is correct. Actually this is one of important concept that we need to understand. I will try to create one session on this.

  • @sunshine3008
    @sunshine3008 Před 2 lety +1

    Someone please help on how to connect to Oracle database and call a stored procedure?

  • @nikhil5062
    @nikhil5062 Před 3 lety +1

    If I watch this whole series , is it sufficient for whole jdbc , have you covered all the concepts.

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před 3 lety

      Yes. From practical perspective JDBC is nothing more than what I have covered in this series. If we talk about interview then most of the questions will be around these concepts only.

    • @nikhil5062
      @nikhil5062 Před 3 lety +1

      @@LearnProgrammingYourself ok I really appreciate you .. because this is one of the best series nowadays I did not find like this kinda videos on youtube I searched a lot but in vain but at last I end up with this serie .
      If there is any more concept related to jdbc so make it full. It l really going to good in future 👍👍

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před 3 lety

      Thanks a lot @Nikhil. Glad to hear this. Your few words will really motivate me towards my work.
      Thanks a lot again.

  • @atharv1312
    @atharv1312 Před 3 lety +2

    Sir, I request you to upload playlist on servlet, Javascript and MVC as well because no channels are there which explains like you

  • @ayushw6773
    @ayushw6773 Před 2 lety +2

    Bro have you added this code on github or somewhere?

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před 2 lety +1

      I am really sorry. I haven't added this code to git but if I find this code now then I will add and share a link.

  • @__sr5806
    @__sr5806 Před 2 lety +1

    sir, for me the issue is "java.sql package is not available",please help me

  • @bhanusiva4k86
    @bhanusiva4k86 Před 7 měsíci +1

    Sir I have a doubt in jdbc connectivity sir could you please resolve this .....

  • @sanjana9727
    @sanjana9727 Před 10 měsíci +1

    Can we consider this as a project or not?

  • @red5hat
    @red5hat Před 2 lety +1

    You have goofed up one of your mistake in the video. Whatever reason you mentioned for error, it was not correct.😂 Anyway, everyone makes mistakes and have doubts and confusion while writing codes. Good job. Keep it up.

  • @nivethat4457
    @nivethat4457 Před rokem +1

    Class. ForName is a exception one

  • @payalgaikwad-xb3ed
    @payalgaikwad-xb3ed Před 2 lety +1

    how to set date format in prepared statement

  • @SAUMILPatel2
    @SAUMILPatel2 Před 3 lety +1

    Exception in thread "main" java.lang.RuntimeException: something went wrong
    at jdbc/com.jdbc.student.StudentDatabase.main(StudentDatabase.java:36)
    its showing this . can you please help

  • @m.aravindkm233
    @m.aravindkm233 Před 3 lety +1

    I am getting java.lang.Runtime Exception see MySQL line 1coming...

  • @ruchaliatkari5123
    @ruchaliatkari5123 Před rokem +1

    I have error in Exception thread main java.lang.RuntimeException please help me please

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před rokem

      if you share me some details like where exactly you are getting exception then I can help.

    • @ruchaliatkari5123
      @ruchaliatkari5123 Před rokem

      Can you give me your e-mail id

    • @ruchaliatkari5123
      @ruchaliatkari5123 Před rokem +1

      Where i can share the details tell me it's urgent please

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před rokem

      If possible you can share me github repository link so that i can look. Or you can directly share me zip file of your project via email. Email id is mentioned in about section of channel

    • @ruchaliatkari5123
      @ruchaliatkari5123 Před rokem +1

      Email id not found in your about

  • @harishkannanmr.awesome3810

    How to dynamically enter the table name also?

  • @angeldaniel9954
    @angeldaniel9954 Před rokem +1

    sir plz help me in this one.
    Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
    enter choice
    1. Insert data
    1
    inside insert record()
    Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.sql.Connection.prepareStatement(String)" because "com.jdbc.student.StudentDatabase.connection" is null
    at com.jdbc.student.StudentDatabase.insertRecord(StudentDatabase.java:42)
    at com.jdbc.student.StudentDatabase.main(StudentDatabase.java:29)

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před rokem

      I think you are not assigning value to the connection and that’s why it is giving null on connection object. Make sure you are assigning value to the connection

  • @dishagangurde3943
    @dishagangurde3943 Před 3 lety +2

    null values are inserted instead of actual values
    plz help

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před 3 lety +1

      Hi Disha, There are couple of ways to handle this case.
      1. Can you please try to print the values before inserting? So that you can make sure you are getting input correctly.
      2. First of all try to insert hard coded values?
      I hope it will help. Please let me know if any help is required.

    • @dishagangurde3943
      @dishagangurde3943 Před 3 lety +1

      @@LearnProgrammingYourself thnx .. turns out it was a silly mistake... Name of variables in java and database were not same

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před 3 lety +1

      That sounds really cool. Thanks Disha

  • @harharmahadev1038
    @harharmahadev1038 Před 2 lety +1

    it says StudentDatabase cannot be resolved to a type

  • @aadityadhamane76
    @aadityadhamane76 Před rokem +1

    can you pls share the src

  • @ranveerkanda
    @ranveerkanda Před rokem +1

    Sir need to contact you urgently, whats the best method?

  • @yogendrasinghpanvar
    @yogendrasinghpanvar Před 2 lety +1

    jdbc connection in Java EE
    Sir Please help me

  • @adityaverma1792
    @adityaverma1792 Před rokem

    Sir facing error since last 3 days can u please help !!!

  • @UjjwalKumar-tv5ms
    @UjjwalKumar-tv5ms Před rokem +1

    PLease help me

  • @ruchaliatkari5123
    @ruchaliatkari5123 Před rokem +1

    I have a error

  • @ruchaliatkari5123
    @ruchaliatkari5123 Před rokem +1

    Can you please help me

  • @spcreation979
    @spcreation979 Před rokem +1

    why are you declaring Scanner as private.

  • @roshanjadhav9204
    @roshanjadhav9204 Před 5 měsíci

    sir please source code comment kardo

  • @user-lj2zr1oh9h
    @user-lj2zr1oh9h Před rokem +1

    The fact that you gave 78% to Sonali, proves that she's your Sister🤣. Am I right?

  • @ruchaliatkari5123
    @ruchaliatkari5123 Před rokem +1

    Hii

  • @abhayransingh1937
    @abhayransingh1937 Před 3 lety +1

    Exception in thread “main” Java.Lang.runtime exception:some went wrong at com.jdbc.student.studentdatabase. Main (StudentDatabase.Java:27)
    Plz reply and help me

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před 3 lety +1

      Can you send me the code where your are inserting values?
      This exception must be because url of database or column and value mapping.

    • @abhayransingh1937
      @abhayransingh1937 Před 3 lety

      @@LearnProgrammingYourself
      package com.jdbc.student;
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.util.Scanner;
      public class StudentDatabase {
      private static Connection connection = null;
      private static Scanner scanner=new Scanner(System.in);
      public static void main(String[] args) {
      StudentDatabase studentdatabase=new StudentDatabase();
      try {
      Class.forName(" com.mysql.cj.jdbc.Driver");
      String dbURL="jdbc:mysql://localhost:3306/jdbcdb";
      String username="root";
      String password="Lipan@1234";
      connection=DriverManager.getConnection(dbURL, username, password);
      System.out.println("enter choice");
      System.out.println("1. insert record");
      int choice=Integer.parseInt(scanner.nextLine());
      switch(choice) {
      case 1:
      studentdatabase.insertRecord();
      break;
      default:
      break;
      }
      }catch(Exception e) {
      throw new RuntimeException("some went wrong");
      }
      }
      private void insertRecord() {
      System.out.println("inside insert record()");
      }
      }
      Sir this is my code plz go through it

    • @abhayransingh1937
      @abhayransingh1937 Před 3 lety

      I send you plz check and reply
      I’m waiting for the replyw

    • @abhayransingh1937
      @abhayransingh1937 Před 3 lety

      @@LearnProgrammingYourself
      Sir please reply....

    • @LearnProgrammingYourself
      @LearnProgrammingYourself  Před 3 lety

      Are you sending the link?

  • @pradeepella
    @pradeepella Před rokem +1

    getting this sir Exception in thread "main" java.lang.RuntimeException: Something went wrong
    at com.jdbc.student.StudentDatabase.main(StudentDatabase.java:38)