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

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 ก.พ. 2025
  • 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 TH-cam GEAR
    www.amazon.in/...
    🌍🌍GET Access to TH-cam 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

ความคิดเห็น • 160

  • @CSCORNERSunitaRai
    @CSCORNERSunitaRai  3 ปีที่แล้ว +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 ปีที่แล้ว

      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 ปีที่แล้ว +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!

  • @Napoledan
    @Napoledan ปีที่แล้ว +1

    You deserve a medal for this. Thanks

  • @adramshapath4720
    @adramshapath4720 4 หลายเดือนก่อน

    Madam Excellent Performance with great detail

  • @IonianWinds
    @IonianWinds 2 ปีที่แล้ว +2

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

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 ปีที่แล้ว +1

      That's great😊 keep watching and plz subscribe

  • @SimplySuman
    @SimplySuman 3 ปีที่แล้ว +3

    So clearly explained ma'am 🙏

  • @joelmarkjmj
    @joelmarkjmj ปีที่แล้ว +2

    OMG Mam you saved me!

  • @truePDJ
    @truePDJ 2 ปีที่แล้ว +1

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

  • @theamazingtutorial.9019
    @theamazingtutorial.9019 ปีที่แล้ว

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

  • @AbdessamadBelm
    @AbdessamadBelm 2 ปีที่แล้ว +2

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

  • @jesty_internm-squared4867
    @jesty_internm-squared4867 2 ปีที่แล้ว +1

    Really Useful one....

  • @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✅

  • @mazedul1448
    @mazedul1448 ปีที่แล้ว +1

    Outstanding

  • @devisri7645
    @devisri7645 3 ปีที่แล้ว +1

    Thank you for clear demo mam

  • @bonissocool4638
    @bonissocool4638 2 ปีที่แล้ว +2

    Thank you so useful for my uni project!

  • @LostMellodies
    @LostMellodies 2 ปีที่แล้ว +2

    Amazing video, very helpful.

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 ปีที่แล้ว

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

  • @health.upgradedbyscience.7309
    @health.upgradedbyscience.7309 2 ปีที่แล้ว +2

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

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 ปีที่แล้ว

      Glad my video helped you👍 keep watching😍

  • @ranad2037
    @ranad2037 2 ปีที่แล้ว +1

    Thanks a lot, you're the best

  • @festussibanda5886
    @festussibanda5886 2 ปีที่แล้ว +1

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

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 ปีที่แล้ว

      Glad to hear that! Keep watching and plz subscribe

  • @zeronetechlearner1546
    @zeronetechlearner1546 3 ปีที่แล้ว +1

    Thanks a million, Madam.

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  3 ปีที่แล้ว +1

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

  • @ruchankayastha3273
    @ruchankayastha3273 3 ปีที่แล้ว +1

    thanks worked like a charm

  • @vijaykrishnagn
    @vijaykrishnagn 3 ปีที่แล้ว +2

    Thank you for the video 😊👍

  • @moalnaim
    @moalnaim 2 ปีที่แล้ว +1

    Thanks you really helped me with this

  • @Programyourmindset
    @Programyourmindset 3 ปีที่แล้ว +1

    Very useful information thank you

  • @SuhanasCreations
    @SuhanasCreations 3 ปีที่แล้ว +2

    Well explained 👍

  • @sarthakgupta096
    @sarthakgupta096 2 ปีที่แล้ว +1

    Thank you mam .

  • @amitdlh
    @amitdlh 2 ปีที่แล้ว +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  2 ปีที่แล้ว

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

  • @developernilesh
    @developernilesh 3 ปีที่แล้ว +1

    Thanks a lot, v nice👍

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  3 ปีที่แล้ว

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

  • @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

  • @amithagolla6907
    @amithagolla6907 3 ปีที่แล้ว +1

    very useful video...

  • @francescalabonte4346
    @francescalabonte4346 2 ปีที่แล้ว +1

    Great video

  • @hplat-vku
    @hplat-vku ปีที่แล้ว

    thank u very muchhhhhh, u helped 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.

  • @Tacoburger22
    @Tacoburger22 2 ปีที่แล้ว +1

    Thank you so much!

  • @jobinninan4481
    @jobinninan4481 ปีที่แล้ว +1

    Thank you

  • @S3Allinone
    @S3Allinone 3 ปีที่แล้ว +1

    Well explained

  • @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

  • @GT-cv3xu
    @GT-cv3xu 2 ปีที่แล้ว +1

    thanks♥

  • @r_nikolov1
    @r_nikolov1 2 ปีที่แล้ว +1

    Thank you so much! =)

  • @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

  • @natarajanparameswaran6752
    @natarajanparameswaran6752 2 ปีที่แล้ว +2

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

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 ปีที่แล้ว

      It works u need just modify according to your table design

    • @natarajanparameswaran6752
      @natarajanparameswaran6752 2 ปีที่แล้ว

      @@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

  • @JoeCee789
    @JoeCee789 2 ปีที่แล้ว +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

  • @gladnn
    @gladnn ปีที่แล้ว

    Would it be possible to make a custom column header instead metadata?

  • @SHEIMANALEKZANDAR
    @SHEIMANALEKZANDAR 2 ปีที่แล้ว +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

  • @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

  • @robert2001101
    @robert2001101 ปีที่แล้ว +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?

  • @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

  • @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 :)

  • @hoangngochieu17
    @hoangngochieu17 2 ปีที่แล้ว +1

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

  • @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

  • @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 ?

  • @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

  • @rajapandey773
    @rajapandey773 2 ปีที่แล้ว +1

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

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  2 ปีที่แล้ว +1

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

  • @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

  • @shaikhibnasazzad
    @shaikhibnasazzad 2 ปีที่แล้ว +1

    How to sort jtable data with the column?

  • @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 ?

  • @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 ปีที่แล้ว +1

    How to do it with date ?

  • @akashbro3786
    @akashbro3786 11 หลายเดือนก่อน +1

    Mem addrow is not found. What i can do?

  • @veeraraghavulu6186
    @veeraraghavulu6186 2 หลายเดือนก่อน

    ActionListerner is not added by default how to do this mam ?

  • @prasannaj384
    @prasannaj384 3 ปีที่แล้ว +1

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

    • @prasannaj384
      @prasannaj384 3 ปีที่แล้ว +1

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

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  3 ปีที่แล้ว

      Eclipse IDE for Java Developers - 2021-06

    • @CSCORNERSunitaRai
      @CSCORNERSunitaRai  3 ปีที่แล้ว

      If you want to get swing related stuffs you need to add WindowsBuilder.
      Refer this video :th-cam.com/video/lctZ-NAWgDU/w-d-xo.html

  • @abunaseribrahimimani
    @abunaseribrahimimani ปีที่แล้ว

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

  • @hirunishamalka3283
    @hirunishamalka3283 2 ปีที่แล้ว

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

  • @AshishKalgutkar
    @AshishKalgutkar ปีที่แล้ว +1

    mam pura code dekha diya hota toh kya ho jaat ?

  • @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;
    }
    }

  • @leandrolara7450
    @leandrolara7450 2 ปีที่แล้ว +1

    Damaste or Thanks or Graciassssssssssss : ,}

  • @WitleRose
    @WitleRose ปีที่แล้ว

    @Eduardoo sai do fake caraio

  • @prernaparwani3074
    @prernaparwani3074 7 หลายเดือนก่อน

    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