How to Get Data from Database to JTable in Java | Display MySQL Data into JTable

Поделиться
HTML-код
  • Опубликовано: 5 сен 2024
  • In this video tutorial, we will build a Simple Application using Swing, JDBC, and MySQL databases in Eclipse IDE for fetching data from MySQL database and display into JTable in Java.
    Mysql Connector for java: dev.mysql.com/...
    ------------------------------------------------------------------------
    Subscribe to my channel for more videos of programming and hit the bell icon to never miss an update in the future.
    Also, don't forget to LIKE & COMMENT.
    ------------------------------------------------------------------------
    Channel Subscription:
    🔗 / cscornersunitarai
    Java Programming Tutorial Playlist
    🔗 • Java Programming Tutorial
    G-Suite Tools Playlist
    🔗 • Videos on G-Suite(Goog...
    Screen Recorder Playlist
    🔗 • Screen Recorder Tools
    Quizzes Playlist:
    🔗 • Quizzes Videos
    Online Teaching Tools Playlist
    🔗 • Videos on Online Teach...
    Thanks for watching my videos till the end, if you like my work please do Subscribe, Like, Comment, and Share!!
    ------------------------------------------------------------------------
    🎥 MY FAVOURITE RUclips GEAR
    www.amazon.in/...
    🌍🌍GET Access to RUclips Influencer Program Worth 999/- ABSOLUTELY FREE using Coupon🌍🌍
    digitalachieve...
    Use this COUPON Code: SPECIALOFFER
    ------------------------------------------------------------------------
    CONNECT WITH ME ON:
    ►Facebook - / cscornersunitarai
    ►Personal Facebook A/c - / sunita.sharmarai
    ►Instagram - / cscornersunitarai
    ►Telegram - t.me/cscorner
    ►LinkedIn - / cscornersunitarai
    ------------------------------------------------------------------------
    #jtable
    #java
    #javaprogramming
    #javatutorialforbeginners
    #javaswing
    #GUI #swing
    Subscribe to CS Corner Sunita Rai for more videos!
    Like! Subscribe! Share!
    Stay tuned!
    PS: Some of the links in this description are affiliate links that I get a kickback from
    ------------------------------------------------------------------------
    populate data from database into jtable, cs corner,sunita rai,jtable java example,jtable in java swing eclipse,jtable tutorial netbeans,jtable tutorial,java swing tutorial,jtable with database connection in java,how to fetch data from database to jtable in java,how to populate jtable data from mysql database,how to connect jtable with database in eclipse,display data from sql database into jtable using java,retrieving data from jdbc database into jtable,display database values into jtables,populate data from database into jtable

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

  • @CSCORNERSunitaRai
    @CSCORNERSunitaRai  2 года назад +4

    *_Got a question on the topic? Please share it in the comment section below and I will answer it for you._*

    • @iamnel3141
      @iamnel3141 Год назад +1

      My codes didn't show anything 😢

    • @sadokfkaier7703
      @sadokfkaier7703 8 месяцев назад

      Same think happened
      @@iamnel3141

  • @7_ajinkya
    @7_ajinkya 2 года назад +6

    so far the only video that shows how to work with JTable and ScrollPane! Thank you so much!!

  • @swanandlaghate5113
    @swanandlaghate5113 11 месяцев назад +2

    Thanks a lot!!!! You have just cleared my 2.5 years long confussion!

  • @preciousjumuad2958
    @preciousjumuad2958 2 года назад +5

    Thank you ma'am! You just saved me from being stuck in a bug for a whole week. May you continue helping programmers, kudos!

  • @dannydevelops
    @dannydevelops Год назад +1

    You deserve a medal for this. Thanks

  • @IonianWinds
    @IonianWinds Год назад +2

    you are an absolute lifesaver!! Thank you so much for sharing this!
    Wish you very happy holidays and an amazing new year! 💞

  • @amitdlh
    @amitdlh Год назад +3

    hello , please how can i solve this problem when I run i get : java.sql.SQLException: No value specified for parameter 1 ! thankyou .

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

      Check out no, of? And r u providing value for all these ? Or not

  • @SimplySuman
    @SimplySuman 2 года назад +3

    So clearly explained ma'am 🙏

  • @definitelynotamexicanskele6913
    @definitelynotamexicanskele6913 Год назад +1

    Thank you so much maam, you're a life saver!!!

  • @mazedul1448
    @mazedul1448 Год назад +1

    Outstanding

  • @AbdessamadBelm
    @AbdessamadBelm Год назад +2

    Great video , straight to the point.
    Thank you so much 👍

  • @natarajanparameswaran6752
    @natarajanparameswaran6752 Год назад +2

    The code doesnt work if I want to retrieve from different tables

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

      It works u need just modify according to your table design

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

      @@CSCORNERSunitaRai suppose I am having 2 tables one with 4 cols and other with 5 then for the second table the 5th col will be empty in jtable as we are reading only 4 columns

  • @health.upgradedbyscience.7309
    @health.upgradedbyscience.7309 Год назад +2

    Great tutorial, thanks a lot! It´s of tremendous help for what I´m working on right now..

  • @joelmarkjmj
    @joelmarkjmj Год назад +2

    OMG Mam you saved me!

  • @robmanda007
    @robmanda007 2 года назад +2

    Hi how are you, Thank you so much for the these tutorials. They are so helpful in my capstone project. May you please do lectures on how to create pie charts, bar graphs and line graphs fetching data from a database.

  • @theamazingtutorial.9019
    @theamazingtutorial.9019 Год назад

    Easy Explained. This video made my knowledge++. Thank you

  • @bonissocool4638
    @bonissocool4638 2 года назад +2

    Thank you so useful for my uni project!

  • @devisri7645
    @devisri7645 2 года назад +1

    Thank you for clear demo mam

  • @festussibanda5886
    @festussibanda5886 Год назад +1

    thank you so much, your video just helped me learn a new concept, keep up the good work

  • @manohartimothy5825
    @manohartimothy5825 2 года назад +2

    Hallo Sunita , I must say that you are a very good teacher and you explained it very well....Thanking you.. I will deffinatly follow you with your more vidios....Manohar

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      Thank you so for your kind words👍
      Your comments motivates me for creating videos. Stay connected✅ God bless you

  • @LostMellodies
    @LostMellodies 2 года назад +2

    Amazing video, very helpful.

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      Glad you liked it👍 do explore my channel for more stuffs

  • @zeronetechlearner1546
    @zeronetechlearner1546 2 года назад +1

    Thanks a million, Madam.

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад +1

      You're welcome👍 Do explore my channel for such more contents

  • @Programyourmindset
    @Programyourmindset 2 года назад +1

    Very useful information thank you

  • @sarthakgupta096
    @sarthakgupta096 Год назад +1

    Thank you mam .

  • @harmonynamai3665
    @harmonynamai3665 2 года назад +2

    Thanks a lot!! You saved my day.

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      Glad it helped you👍Do explore my channel for more stuffs✅

  • @jesty_internm-squared4867
    @jesty_internm-squared4867 Год назад +1

    Really Useful one....

  • @moalnaim
    @moalnaim Год назад +1

    Thanks you really helped me with this

  • @vijaykrishnagn
    @vijaykrishnagn 2 года назад +2

    Thank you for the video 😊👍

  • @MessiSwag10
    @MessiSwag10 Год назад +2

    Thank you so much for the helpful video! I do have a question though. In your program, you knew the amount of columns before hand, so you were able to create the no, name, and makrs variables. Is there an alternate way to do this if you don't know what your column size will be?

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  Год назад +1

      Yes you can use ResultSetMetaData interface.
      It's having method through which you can get column count.

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  Год назад +1

      Refer my advanced java playlist. I have shown in one video

  • @SuhanasCreations
    @SuhanasCreations 2 года назад +2

    Well explained 👍

  • @jobinninan4481
    @jobinninan4481 11 месяцев назад +1

    Thank you

  • @hoangngochieu17
    @hoangngochieu17 Год назад +1

    Could you tell me why I can't run JinternalFrame after extending it...

  • @ruchankayastha3273
    @ruchankayastha3273 2 года назад +1

    thanks worked like a charm

  • @amithagolla6907
    @amithagolla6907 2 года назад +1

    very useful video...

  • @ranad2037
    @ranad2037 Год назад +1

    Thanks a lot, you're the best

  • @S3Allinone
    @S3Allinone 2 года назад +1

    Well explained

  • @hplat-vku
    @hplat-vku 8 месяцев назад

    thank u very muchhhhhh, u helped me

  • @francescalabonte4346
    @francescalabonte4346 2 года назад +1

    Great video

  • @robert2001101
    @robert2001101 9 месяцев назад +1

    Thank you for the helpful code tutorial. I'm having an issue with the column names not displaying properly though, they only show java.lang.String or java.lang.Integer. Could you help me with this please?

  • @pasha7748
    @pasha7748 2 года назад +2

    Hi, could you please tell me, where i can find the Table control name (in your case tblData)? Because when i use tblData and declare it in class, there is an error, which says: cannot invoke javax.swing.jtable.getmodel() because tblData is null... I dont know how to fix this. Could you please help me?

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад +1

      It's available in toolbox where u can see available controls just drag and drop

  • @SHEIMANALEKZANDAR
    @SHEIMANALEKZANDAR Год назад +1

    Hi ma'am May i know how do view table without clicking a button! Like an Example when i run the program automatically The records from the database should show

  • @JoeCee789
    @JoeCee789 Год назад +1

    So i'm using NetBeans and i seem to have a problem with the tblData read the comments and couldn't find a working solution how do get the tblData to work

  • @developernilesh
    @developernilesh 2 года назад +1

    Thanks a lot, v nice👍

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      Glad you liked it👍Do explore my channel for more stuff

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

    Hello, Mam. I want to display data in a table. The data are fetched from an excel.xlsx file stored in my local drive. How to do that preferably in IntellijIdea ?

  • @LeticiaGAlves
    @LeticiaGAlves Год назад +1

    THANK YOU SO MUUUUUCH!!

  • @shaikhibnasazzad
    @shaikhibnasazzad Год назад +1

    How to sort jtable data with the column?

  • @endmysuffering6847
    @endmysuffering6847 2 года назад +1

    Hello, the first row ( the topmost ) is not showing up on the table how can I fix?

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад +1

      Ok I'll check.. When I tried it was working

    • @endmysuffering6847
      @endmysuffering6847 2 года назад

      @@CSCORNERSunitaRai I can send you my code because mine is alittle different from yours. Great vid btw!

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      @@endmysuffering6847 ok u can share on my telegram @cscorner

    • @endmysuffering6847
      @endmysuffering6847 2 года назад +1

      @@CSCORNERSunitaRai I was able to fix it I had to add the table to a jscrollpane. Thank you for responding still :)

  • @marshyadav7885
    @marshyadav7885 2 года назад +1

    model.setColumnIdentifiers() method is not displaying names of columns, no errors. Any solution?

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      Did you placed ur jtable control properly?
      Follow the way I have shown. Delete and place again

  • @rajapandey773
    @rajapandey773 Год назад +1

    I am getting this issue...
    Unable to parse source.
    WindowBuilder was not able to parse source private javax.swing.JTextField textField;.

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  Год назад +1

      Declare this variable in class not in constructor. Only Initialization in constructor

  • @arifhussain9676
    @arifhussain9676 2 года назад +1

    THanks for the video, every time i press show button, It makes duplicate and show it on table. Can we do something so that no duplicate record shows on table

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      Check addRow method.
      Did you wrote it twice?

    • @arifhussain9676
      @arifhussain9676 2 года назад

      @@CSCORNERSunitaRai I wrote it one time but I press button twice or when you press button again and again, you get duplicate rows.

  • @eshaesha9100
    @eshaesha9100 2 года назад +1

    another question respected mam. How do i know which commands to use in the action Listener method. like you wrote so many command, database connectivity etc.. I mean is there any good guide for beginners?

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад +1

      This question is wrt to what ?
      If u r asking related to jdbc then depending on buttons we hv to write code

    • @eshaesha9100
      @eshaesha9100 2 года назад +1

      @@CSCORNERSunitaRai yes mam, it is mainly related to jdbc

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      @@eshaesha9100 ok so when u click on add button write insert code, delete button write delete code and so on

  • @reizsax
    @reizsax 2 года назад +1

    Please help, my ‘rs.getMetaData()’ is error. It suggests that I add cast to ‘ResultSetMetaData’ or change type of ‘rsmd’ to ‘ResultSetMetaData’. And even though I followed the suggestions, the table data still doesn’t show.

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад +1

      Check your import. All jdbc related import should be from java.sql only

  • @Tacoburger22
    @Tacoburger22 2 года назад +1

    Thank you so much!

  • @GT-cv3xu
    @GT-cv3xu Год назад +1

    thanks♥

  • @abusolo_3255
    @abusolo_3255 2 года назад +2

    7:52 you said "tblData" is your table name, but isn't your table name is "student"?

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      I mean JTable control name.
      Thanks

    • @abusolo_3255
      @abusolo_3255 2 года назад

      @@CSCORNERSunitaRai where can i find my JTable control name?

    • @abusolo_3255
      @abusolo_3255 2 года назад

      @@CSCORNERSunitaRai it shows me error in this line (under the "tblData" exactly ) DefaultTableModel model=(DefaultTableModel) tblData.getModel();

    • @abusolo_3255
      @abusolo_3255 2 года назад

      and one of the solutions the program tell me to create local variable to "tblData"

    • @abusolo_3255
      @abusolo_3255 2 года назад

      never mind, it work fine now, thanks, i just replaced "tblData" to "table" and it worked haha

  • @akashbro3786
    @akashbro3786 6 месяцев назад +1

    Mem addrow is not found. What i can do?

  • @r_nikolov1
    @r_nikolov1 2 года назад +1

    Thank you so much! =)

  • @eshaesha9100
    @eshaesha9100 2 года назад +1

    respected mam, do we need any extension for the JFrame and the design view in Eclipse?

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад +2

      If u want to use eclipse u need to add window builder

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад +2

      Detailed tutorial on how to create swing in eclipse available on my channel under advanced java tutorial playlist

    • @eshaesha9100
      @eshaesha9100 2 года назад +2

      @@CSCORNERSunitaRai yes mam, i just watched that tutorial. You are legend mam

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад +1

      @@eshaesha9100 thank you so much dear👍please share

  • @saronaraphaelv.5878
    @saronaraphaelv.5878 2 года назад +1

    Hello maam can you help me mine says no sutiable driver found

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      Join my telegram and Please share screenshots of error. I will try to fix it

  • @samoli02
    @samoli02 9 месяцев назад +1

    How to do it with date ?

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

    Actually, I have another function in a different package that does the fetching part using a class in another package, How can I display data using that function, here are the functions:
    public ArrayList findAllStudent() {
    ArrayList al=new ArrayList();
    conn=ConnectionPool.connectDB();
    String query="select * from student";
    try {
    Statement stmt=conn.createStatement();
    ResultSet rs=stmt.executeQuery(query);
    while(rs.next()) {
    StudentBean sb=new StudentBean();
    sb.setEnrollmentno(rs.getString("Enrollment"));
    sb.setName(rs.getString("Name"));
    sb.setAddress(rs.getString("Address"));
    sb.setBranch(rs.getString("Branch"));
    sb.setCollege(rs.getString("College"));
    sb.setSemester(rs.getInt("Semester"));
    sb.setGender(rs.getString("Gender"));
    sb.setSubject1(rs.getFloat("Subject1"));
    sb.setSubject2(rs.getFloat("Subject2"));
    sb.setSubject3(rs.getFloat("Subject3"));
    sb.setSubject4(rs.getFloat("Subject4"));
    sb.setGrade(rs.getString("Grade"));
    al.add(sb);
    }
    conn.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return al;
    }
    The connectionpool class:
    public class ConnectionPool {
    static Connection conn;
    public static Connection connectDB(){
    try{
    // register driver
    Class.forName("com.mysql.cj.jdbc.Driver");
    // create the connection
    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/studentdb","root","space");
    System.out.println("Database connected");
    } catch (ClassNotFoundException ex){
    ex.printStackTrace();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return conn;
    }
    }

  • @abusolo_3255
    @abusolo_3255 2 года назад +1

    if i want to display only 1 row, how i can do that?

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      You can use following method:
      jTable1.getModel().setValueAt(daya,row_index,col_index)

    • @abusolo_3255
      @abusolo_3255 2 года назад

      @@CSCORNERSunitaRai can you please tell me where exactly to put this line ?

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

    Madam, please can I request for a demo on adding pagination on Jtable using eclips

  • @AshishKalgutkar
    @AshishKalgutkar Год назад +1

    mam pura code dekha diya hota toh kya ho jaat ?

  • @hirunishamalka3283
    @hirunishamalka3283 2 года назад

    how to get data from database to JTable in selected one column

  • @prasannaj384
    @prasannaj384 2 года назад +1

    What is this eclipse ide version mam?
    Send the comment box that link

    • @prasannaj384
      @prasannaj384 2 года назад +1

      Because that swing set that package not available mam in my ide

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      Eclipse IDE for Java Developers - 2021-06

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад

      If you want to get swing related stuffs you need to add WindowsBuilder.
      Refer this video :ruclips.net/video/lctZ-NAWgDU/видео.html

  • @leandrolara7450
    @leandrolara7450 2 года назад +1

    Damaste or Thanks or Graciassssssssssss : ,}

  • @WitleRose
    @WitleRose 10 месяцев назад

    @Eduardoo sai do fake caraio

  • @prernaparwani3074
    @prernaparwani3074 2 месяца назад

    Java.awt . eventdispatchthread exception occurred

  • @babyph65
    @babyph65 Год назад +1

    getModel() is not working on me

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

      Is it showing any error

    • @babyph65
      @babyph65 Год назад +1

      @@CSCORNERSunitaRai my compiler has some error so I re- installed it, its fine now. Thanks ♥️

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

      @@babyph65 yes

  • @Nishantkumar-sr2bu
    @Nishantkumar-sr2bu 2 года назад

    maam i got a problem with tbldata.getModel() its showing that it can't be resolved please help

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 года назад +1

      Declare tblData inside class. It's not able to find variable tblData