JFrame and Databases Part I

in #java7 years ago (edited)

So, after hours upon hours of research (a little over 12 hours) I finally found how to create a folder AND a database inside that folder. So, I want to help those who have been trying to do this.

Firstly, You wanna make sure that you have installed the JDBC Driver. This allows you to connect to the database that we will be making later. Keep this in mind.
Secondly, You need to know HOW a SQL Database works. In order to add items to the database, you must first create it and tell the database "Hey, I am taking this info and adding it to you, here are the values, can you do that?" And it will, if set up correctly. If there is EVER an error, it will be caught inside the catch statement. This helps developers pin point the issue and find a fix for the phenomenon. Alrighty. Enough chatter. Lets get coding!

Now, with this code, I will be using JFrames toassist on understanding on how the database works.
This is a simple JFrame with four things: A JLabel, JTextField, and two JButtons. The JTextField is, lack of better terms, parsed as a string as it is taking in text. This wont cause a problem in our database as that's all we are logging. The submit button allows us to "edit" the database and add to it.

Simple JFrame:
SteemItJFrameExample.PNG

Think of this as a way to "interact" with the database per se. So, now that we got that defined. Time to connect to the database. As said previously, we will be connecting to the Database that is accessed inside the computer. The way the JDBC works is that it scans your computer in the directories and if it doesn't find the file, it'll throw you an error from the catch statement. After installing the JDBC, you can connect to the database.

Connect to the Database:
ConnectToDatabase.PNG

"What if the database that we are looking for with the JDBC isnt there?" Simple fix. If you want to pass this code to someone else (this is scary btw), you can code the program to create the database for you.

Create The Database and Its directory:
createthedatabase.PNG

SUMMARY
Connecting to a Database using JDBC
Creating a Database that isnt there
Creating a JFrame
Taking data from a JFrame and uploading to the Database
Some SQL Basics

Unfortunately that's all the time I have. I will post part II soon. Stay Tuned :P

Sort:  

Hey! Make sure to tag this in #steemiteducation. Nice work man!

Coin Marketplace

STEEM 0.22
TRX 0.26
JST 0.040
BTC 96371.40
ETH 3383.73
USDT 1.00
SBD 3.17