Java Video Tutorial 37

Java JTables MysqlIn this part of my Java Video Tutorial, I continue showing how to use JTables with MySQL. You’ll learn how to pull information from a database, add a row, delete a row, convert a String into a SQL Date and much more.

If you haven’t seen my Java Swing Tutorial watch it first. Part 1 of my Java JTable Tutorial should also be seen first.

I explain how to load the database below. I also have all of the code.

If you like videos like this tell Google [googleplusone]

How to Load the Database

You’ll need to do the following to read info from the database:

  • Open MySQL and create a database with CREATE DATABASE samp_db;
  • Type the following USE samp_db;

Exit MySQL and download these files:

Then execute these to commands in your terminal (outside of MySQL):

  • mysql5 -u YOURUSERID -p < YOUR create_president.sql LOCATION
  • mysql5 -u YOURUSERID -p < YOUR insert_president.sql LOCATION

Use your USERID and PASSWORD. Point to the locations for where you saved the files above. That’s it.

Code from the Video

27 thoughts on “Java Video Tutorial 37”

    1. Thank you 🙂 I’m always looking for ways to improve. Is there anything I could do better? Are there any other topics you’d like to see covered? I’ll cover pretty much any topic

      1. Thank you so much for your tutorials. They are so far the best of all java tutorials I’ve seen on youtube. It would be nice to extend tutorial #36 and 37 to sorting and filtering of jTable. Is sorting and filtering possible with DefaultTableModel?

  1. You already have done a lot for us, and beside my academic study i m practicing web design from you tutorial which isnt finished yet, i check and like your every video and the way u teach us. but im far away from this advance tutorial, but im happy and now im practicing psd to html and fixing bug. pray for me , wish you all the best 🙂 Thank you

    1. Thank you. After you really understand one language you’ll be able to easily learn the rest. If you are ever struggling with a tutorial you can normally work your way through the problem by playing with the code in your own editor. If my comments aren’t good enough you can then look up the functions in the API. It takes awhile, but eventually everything just clicks. When that happens you’ll be able to do anything. I wish you the best

  2. Thank you very much for your tutorials, helped me a lot on my school projects, keep up the good work !
    Greeting from Morocco!

  3. Your code is working correctly.

    I just want to mention something; (I am not sure whether it is good) but here it is.

    Once you have imported JFrame(line 16) , and created new JFrame (line 67), Then you don’t need to extends your class by JFrame (line 24).

  4. Hi Derek,

    Thank you so much for these tutorials. As an aspiring Java developer/student, I am interested in creating Java-based applications that interface with relational databases..

    Instead of hard coding the columns, i decided to use a metadata from the previous tutorial. However, i keep getting “Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 4:” error.

    Here is my code –
    static Object[] columns;(at the class level)
    columns = new String[numOfCol];

    for(int i=1; i<=numOfCol; i++)
    {

    // Returns the column name

    columns[i] = metaData.getColumnName(i);
    System.out.println(i);

    }

    the console prints numbers 1-3.

    Thank you for your help.

  5. You’re right about things clicking. I’ve been working on Java really hard and suddenly going back to PHP and JS things seem a lot clearer in my head.

    I’m experimenting with my own database at the mo and was wondering.. What is the purpose of overriding the getColumnClass method?

  6. Hi Derek,

    question:
    – Why a zero (0) in getValueAt(0, column)of overidden method getColumnClass(Lesson 37)?

    Also, job well done on (all that I have viewed so far) video tutorials.

    The video format works well with me. The explanation, timing and focus of the lessons and key points are cohesive. You also have a good way of conveying them.

    thanks,
    eazl

    1. Hi Eazl,

      I’m glad you like the videos. Here is the description of the method getValueAt : public Object getValueAt(int row, int col)

      Since I’m only getting the columns with this class, that is the reason I keep row at 0. I hope that helps 🙂

      Derek

  7. Hi!

    This is a great tutorial, but iI’m having trouble getting the data from mysql. I’m using MAMP. Do I need to change something on the connection url or to MAMP’s configurations? Because I keep on getting “SQLException: Communications link failure” on the console.

    Any help would be appreciated. Thank you.

    Maria

  8. Hello Mr. Banas

    Thank you for the awesome tutorial and assistance. I’m having trouble adding a president because each time I do so the month ends up being October, the day is always the first, and the year always increments by one then what I inputted. Is there any reason why this is happening?

  9. I cannot seem to add the sql files to mysql. I keep getting this error. ERROR 1046 (3D000) at line 1: no database selected

    I use the:
    #mysql -u root < C:\downloads\insert_president.sql

    Thank you for the great tutorials also. So far so good.

Leave a Reply

Your email address will not be published. Required fields are marked *