HomeХобби и стильRelated VideosMore From: Steven Byrne

Java- MySQL Connection (Create Table, Insert, Select)

769 ratings | 264745 views
This is a fast tutorial, intended for people who understand java, and the basics of SQL/MySQL who just want to see how to use my-sql-connector. How to create a MySQL Connection in java, then create a table, insert, and select, video 1 of 4. CODE: import java.sql.Connection; import java.sql.DriverManager; public static Connection getConnection() throws Exception{ try{ String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://24.196.52.166:3306/testdb"; String username = "username"; String password = "password"; Class.forName(driver); Connection conn = DriverManager.getConnection(url,username,password); System.out.println("Connected"); return conn; } catch(Exception e){System.out.println(e);} return null; } Download JDBC https://dev.mysql.com/downloads/connector/j/ --06/07/2107
Html code for embedding videos on your blog
Text Comments (181)
Worldhomicide (1 year ago)
The link you provided in the video doesn't seem to be working. Any help? (For Connectors)
Steven Byrne (1 year ago)
Thank you for letting me know, they moved the link here: https://dev.mysql.com/downloads/connector/j/
Chika (12 days ago)
what if I'm using netbeans? I can't find "JRE system library"
Steven Byrne (10 days ago)
I believe in netbeans you go to: Projects --> Right click Libraries --> Add JAR/Folder --> Select the JAR file for SQLite you downloaded --> Check to make sure it worked! I haven't used Netbeans in years, but I'm sure it will be similar to that; good luck!
Ananya Ghoshal (1 month ago)
I'm getting a ClassNotFoundException....how shall it be resolved?
Steven Byrne (1 month ago)
ClassNotFound is raised normally when there is either a typo in the connection string, or it can't find the Jar file for SQLite; double check your connection string doesn't have any typos and make sure your SQLite jar is configured in the build path so Java can find it. Good luck!
ALLSTARS-Z0R0 (2 months ago)
Ahh a miracle, not some idian guy!
bharat arora (2 months ago)
Thnx a lot i was struggling a lot to establish this connection 🖒
Steven Byrne (2 months ago)
Glad I could help, good luck!
i have a project which i am going to use java as a Restful Back- end using springboot i heard that the there is something in java that will build the tables automatically in the database for me can you tell me what is this magical thing called ?
Steven Byrne (2 months ago)
I'm not aware of any magic that will automatically make the database in Java, however there are some near magical tools like MySQLMaestro (https://www.sqlmaestro.com/products/mysql/maestro/) that let you build databases/tables with a GUI so you don't actually need any code to make them; in most cases though I'd suggest against this because if you're making a restful API chances are you will want to be able to make the tables again with slight modification for future versions, so I feel it would be better to just have a dbsetup class that you run once to create the DB/tables/users. That does mostly come down to preference though as you can copy/alter tables in MySQLMaestro if you wanted to
Tahmid Islam (2 months ago)
What account and password are u talking about can u explain please?
Steven Byrne (2 months ago)
The username/password will be to get access to MySQL. If you install MySQL on your computer it will have you setup an account (username: root, and an optional password). If you use a web host or database host they often provide you a username and password or give you access into the MySQL command line to create one... Easiest way for testing would be to install MySQL locally (or on your server if you have one) and setup a new user/password in the MySQL console (or something like PHPMyAdmin)
vignesh kumar Pandian (3 months ago)
I tried to run the code but it shows the Exception Unknown database 'testdb' . What should I do to resolve this
vignesh kumar Pandian (3 months ago)
thanks !! the video really helps!
Steven Byrne (3 months ago)
vignesh kumar Pandian  Glad to see you already got it; if you wanted to connect without specifying a database (normally before you create one) you'd just drop the "testdb" from the end of your url string so: jdbc:mysql:server:port/ instead of: jdbc:mysql:server:port/dbname
vignesh kumar Pandian (3 months ago)
nvm. i wrote create database testdb in console and then tried to run it and it worked
rohan chowdhury (3 months ago)
Which software you are using for writing the Java code?
Steven Byrne (3 months ago)
Eclipse, it's a really nice editor! https://www.eclipse.org/
Ansh (4 months ago)
when i execute the program error occurs "java.lang.classnotfoundException:conn.mysq.jdbc.Driverl". i dont know where i went worng edit:i made database on mysql not on mysql workbench. and didnt add jar/project?
Steven Byrne (3 months ago)
Glad to hear it!
Ansh (3 months ago)
thanks it works.
Steven Byrne (4 months ago)
The Jar file has to be added to eclipse for it to know how to talk to the database, try adding the Jar to the build path and see if that takes care of the error
Łukasz S.kyWalker (5 months ago)
Big thx!!
krishna budania (5 months ago)
Nice..
Vegard Fjeldberg (6 months ago)
We are going to learn how to create a tae? What's that?
Steven Byrne (6 months ago)
Vegard Fjeldberg most of my jokes are lame :p
Vegard Fjeldberg (6 months ago)
I was referencing the last few seconds of the video where you cut a little too much. Therefore I asked what a tae was and not a table. Yeah I know, very lame joke.
Steven Byrne (6 months ago)
Vegard Fjeldberg you can think of tablets like an excel spreed sheet, we have columns (a,b,c ect) and rows. The columns tell us what data should be in the rows, for instance first name in column a, last name in column b, and the rows contain the acutal data like: steven, Byrne... you can hold all of these tables inside a database to help with organization, for instance you might have a user's database that holds 2 tables, authentication holding passwords and usernames, and another holding user preferences like profile pictures, time zone, ect
Gnar Prod (6 months ago)
it works thank you
Beats basteln :3 (9 months ago)
i get the following error: "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server." you know what i'm doing wrong?
Steven Byrne (9 months ago)
Beats basteln :3 you're welcome, good luck and let me know if you have any trouble!
Beats basteln :3 (9 months ago)
perfect! thank you
Steven Byrne (9 months ago)
I would use/look at SQLite than; its portable, doesn't need a server and is almost the same as MySQL; I made two videos on it here: https://www.youtube.com/watch?v=s80sAEbF9Fk And here: https://www.youtube.com/watch?v=YNYojrtKMXo
Beats basteln :3 (9 months ago)
thank you for the quick answer. i don't understand why i have to use a server at all tbh. i just want a database for my offline programm. nothing that should need urls and stuff
Steven Byrne (9 months ago)
Normally this is caused by using the wrong ip address, assuming you have your MySQL server installed on the same computer you are running your java applet on, try changing the IP address to: LOCALHOST:3306 or your local ip address if you're using localhost now; I'd take a look at this Stackoverflow post and see if those answer help if mine didn't: https://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai Best of luck!
Dragan Pajic (9 months ago)
Thanks Steven. You help me very good
yoru (9 months ago)
hi sir!! i've made a projet with Java using derby for my database!!! how can i now make a setup ? i mean i need the data base with the code!! any help plz?
Steven Byrne (9 months ago)
Okay, so if you are making a portable database MySQL won't really work; you have to have MySQL installed to use, you could have a server host it and just have Java connect to your server but it sounds like you want to package the database with your project (not require an internet connect to connect to a hosted database). For that you would use something like SQLite; very similar to MySQL but portable. I've made two videos on this topic, one using the SWING library for a front-end to the SQLite database here https://www.youtube.com/watch?v=YNYojrtKMXo the other using just SQLite without the fancy GUI (which is a much shorter video if you just want to learn how to use SQLite) which you can watch here: https://www.youtube.com/watch?v=s80sAEbF9Fk
yoru (9 months ago)
yes!! i want to know how can i make a portable database !!
Steven Byrne (9 months ago)
Are you looking to compile your java project with the existing database?
SuperSwag900 (11 months ago)
I keep getting the following message: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Not sure if my SQL server on my local host is set up properly but it says the server is Online
Steven Byrne (11 months ago)
Try a few of the trouble shooting listed here: https://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai One of the first things I'd try is using your "loopback" Ip address (127.0.0.1) instead of the LOCALHOST name or visa versa and see if that helps
Param Oza (11 months ago)
I keep getting a communications link failure. I've entered in my root username and password for MySQL. Any idea as to why this is?
Steven Byrne (11 months ago)
What's the exact error message? Is the MySQL server installed on the same computer you are running your Java code from, or is it a remote server?
siri valli (1 year ago)
this video was very clear in a short time, really good
Steven Byrne (1 year ago)
Glad it helped!
Lee Lounsbury (1 year ago)
Thanks! Finally got it to work
rostom mamadji (1 year ago)
How did this work with phpmyadmin?? And how can i know that i am connected to the data base?
Steven Byrne (1 year ago)
It sounds like the functions are not being called, add some System.out.print("ALIVE"); statements in your code to see what lines are firing
rostom mamadji (1 year ago)
Steven Byrne I follow your tutorial till the end but nothing happened.. When I run I do not got errors but when I check phpmyadmin I do not find any. New data base... So where is the problem and how I get into it.. I also did the next tutorial and any table was created.. Help me please. Thnx
Steven Byrne (1 year ago)
PHPmyAdmin is a MySQL management tool, it doesn't really integrate or work with anything besides MySQL databases/tables/users/ect. If your function throws an error you will not be connected. If it gets to your print statement without an error than you have connected. Checking your connection is doable but is often unhelpful as it won't tell you anything more than the initial connection did. Allot of people will run a SELECT id FROM example_table LIMIT 1 to check if they can select data before executing their command but it really just depends on what you are trying to accomplish
Random User (1 year ago)
So if I use an SQL database will other users be able to use my program if I send them the jar file? Will they need an internet connection to connect to the host? How would I go about writing an app that creates a local database in the user's computer? As you can see Im quite a newbie.
Steven Byrne (1 year ago)
Yes, everyone got out and is doing fine so I can't ask for much more than that! There are a few examples/tutorials I read here: http://www.sqlitetutorial.net/sqlite-java/sqlite-jdbc-driver/ Or a list of them all here: http://www.sqlitetutorial.net/sqlite-java/ That will help get you started with SQLite and Java, really it is very similar to MySQL just that one is local and the other is on a server. If you run into any trouble feel free to reach out and I'll do my best to help!
Random User (1 year ago)
Steven Byrne Thank you very much for your reply (and therefore time). I will look for SQLite. I used to code Java when I was 13 but gave up on it once my programs started requiring databases so Im just trying to go back into the business. I am also sorry to hear that your house was damaged, hope you and your loved ones are ok.
Steven Byrne (1 year ago)
Okay, so generally speaking, if you use MySQL that will require a public internet connection to access the database. It works on your computer without one assuming you have MySQL installed but most users will not have it installed. The two ways around this would be either have a public IP address or host name (like Google.com or Robertsroom.com are both public hosts with a static IP to access them) or to use something like SQLite. MySQL requires a server and is great for centralized data (like comparing high scores in Call Of Duty). SQLite does not require a server and is great for local data like saving a programs settings. To create an app using a local database you can either add a dependency of MySQL (Basically tell people they need to have a MySQL server running and installed before using your app) which isn't normally recommended, though there are cases when this is necessary. OR Use something like SQLite which will create the database "on the fly" and can be used offline. I'd suggest looking at SQLite. I was working on a tutorial with SQLite and Swing but that has been delayed (my house burnt down on Wednesday so I don't have any of my files or recording stuff)
WeMissOldTibia (1 year ago)
Learn to use classes
n McG (1 year ago)
gonna go ahead then go ahead and after that go ahead?
Beat Cent (1 year ago)
Great!!
sharath sunny (1 year ago)
helo....i got a communication link failure...!!!!!!
Steven Byrne (1 year ago)
I'd take a look at this post, sounds like it is normally a slight miss configuration on the MySQL server: https://stackoverflow.com/questions/6865538/solving-a-communications-link-failure-with-jdbc-and-mysql
sharath sunny (1 year ago)
Steven Byrne ... it was...com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: communication link failure... tye last packet sent sucessfully to server but driver has not recieved any packets from server
Steven Byrne (1 year ago)
What was the exact error message?
iceshadow625 (1 year ago)
The throws Exception will never throw anything as it is already caught and "handled" in the catch clause of your try. Of course you might eventually pass the error upwards, in which case it'd be used, but as for now, it is technically dead code.
Steven Byrne (1 year ago)
I completely agree, unless you end up passing the error up the stack you can remove it... I feel try catch works much nicer in this situation also (depending on the situation this might change though)!
Rodolfo Morales (1 year ago)
Great work! I have an issue when I run the code: WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Any help please?
Rodolfo Morales (1 year ago)
That was way too fast, Thanks!
Steven Byrne (1 year ago)
Here's the solution, in your connection string use add this: ?useSSL=false; So the whole string should look like this: String url = "jdbc:mysql://24.196.52.166:3306/testdb?useSSL=false"; Basically SSL is an encryption method to make sure your data stays secure in transit, if you do no use it (set it to false) then anyone on your network COULD see the data you are sending to MySQL. For development ssl being off is fine, but for applications you should always use SSL (by changing it to true). Because of the way SSL works, you need to verify the server, which can be difficult for new users so I would suggest using the connection string like this: String url = "jdbc:mysql://IP:3306/DATABASE?verifyServerCertificate=false&useSSL=true";//what this does it it uses SSL so your data is encrypted, but it does not authenticate the server, IE it leaves you vulnerable to whats called a man in the middle attach where someone pretends to be your server that isn't, but for testing and development won't be sending things like your username/password openly across the network. For the final product (like an app or program) you should make sure SSL is enabled in the MySQL server and require SSL in your program to make sure you're not going to be sharing information that is supposed to be private.
Fuat Imanov (1 year ago)
Hi, should we write connection code under "public static Connection" ? I am new to java, I dont know why we wrote codes under it?
Steven Byrne (1 year ago)
You are welcome, hope it helped!
Fuat Imanov (1 year ago)
Steven Byrne Thank you very much.
Steven Byrne (1 year ago)
The term public is the access type, basically who's (what's) allowed to use this function, the return type, that is the information we are going to be giving back is a Connection (which is what we call a datatype). Later we call this getConnection() function (it always goes in order: Access Type [public], Return Type [Connection], Name [getConnection], Arguments [none in this case], exception handling [optional]. by writing the code here and then later calling it, we can use the same lines of code without having to rewrite them over and over. By the way, the static keyword means it is unchanging and is also an option "setting" of the function if you will
StickMan1316 (1 year ago)
can you use a data base thats from a free webhosting website like 000webhost? By the way I am using the sub domain version if that helps you
Steven Byrne (1 year ago)
000webhost specifically doesn't allow this. Any server that has "Remote MySQL Enabled" you can connect to using either the IP address (something like 123.123.123.123) or by hostname (youtube.com or mysqlserver.net) excluding any subdomains (don't use them in your connection string, so my.domain.com would just be domain.com)
Abdul Malik (1 year ago)
Hi Steven, Good video. What is the purpose of the code "Class.forname", i had this is my code but then I commented it out and yet I was able to establish connection to DB and was able to execute my queries and get results. I will keep it commented unless I find the reason for using it
Steven Byrne (1 year ago)
Generally speaking it registers the class as a driver or to be more specific what it does it "forName() method, just return the Class object for the parameter that was loaded [our mysql jar class object]" There are more details on what it's used for here: http://stackoverflow.com/questions/15039265/what-exactly-does-this-do-class-fornamecom-mysql-jdbc-driver-newinstance
sunidhi naik (1 year ago)
Do we have to create an account for this???where so in oracle
sunidhi naik (1 year ago)
K thx👍
Steven Byrne (1 year ago)
Well the basic steps are: 1) Install MySQL 2) In the MySQL console (installed with MySQL) create a username and password. 3) In the MySQL console create a database or create on in the Java code using something similar to: CREATE DATABASE yourdatabasename 4) write your java code using your proper username/password, host, database name, table name, field names, ect.
sunidhi naik (1 year ago)
Just we hav to install mysql to get the username n Password right Nothing else to be changed in the code????
Steven Byrne (1 year ago)
sunidhi naik you need to download the jar from the website in the video, you won't change anything in that jar. the jar is what let's you talk with your server
sunidhi naik (1 year ago)
As changes to be made in that
oumayma oulahou (1 year ago)
merciii
Viktoria Pushkina (1 year ago)
I did everything as u said and as it showed in video but it didn`t work! There`s no errors, but it is just empty concole after "Run"
Steven Byrne (1 year ago)
If your program is running it should at least show an execution time in the console. Make sure you call the functions from the public static void main(String[] args) function. Try adding a print statement in the main function to make sure the program is starting and you're in the correct console viewer
raphael borja (1 year ago)
It always shows an error "unknown database"
Steven Byrne (1 year ago)
raphael borja did you run a create database command?
Divyansh Jain (1 year ago)
Hello Steven. Greetings from India. I have a question: Why have you used "try/catch" block and "throws" statement both together in one class. You could have used either of the two??
Divyansh Jain (1 year ago)
Okay. Thanks Steven. :)
Steven Byrne (1 year ago)
Yes, the reasoning for both was simply so the IDE didn't turn the function red while I was making the try statements. For production you should pick one and stick with it (I prefer try/catch myself)
Michael D. (1 year ago)
nice 'shit' folder on your desktop
Dikshanta Ghimire (1 year ago)
Hello. You are the greatest. Can I use this on Android Studios aswell.
Steven Byrne (1 year ago)
Good luck, let me know if I can answer any questions!
Dikshanta Ghimire (1 year ago)
My issue was I was using XAMPP as my sql server and it just wasn't connecting. I'll keep trying.
Steven Byrne (1 year ago)
Was the connection giving you an error? Never give up, there is always a work around but sometimes you need to take a break and look at it from a different perspective. If you've got any questions I'll do my best to answer them!
Dikshanta Ghimire (1 year ago)
Thank you. I did something very similar to you but my connection wasn't working. Ill keep trying. You actually gave me confidence not to give up. :) Would you mind if i ask you few simple I may have in future.
Steven Byrne (1 year ago)
I'm not sure exactly how Android Studios handles it, but you should be able to, or something very similar! Best of luck!
דור דורניק (1 year ago)
wow you not e indien/pruttcky
Basci programming (1 year ago)
hahahahahaha
Varry Moonlight (1 year ago)
Sir where did the userid and pword came from?
Steven Byrne (1 year ago)
Evaristo Simbulan user ID and password are setup on your MYSQL server. when you install MySQL it will ask for you to set this up
XeroX1907 (2 years ago)
I get the following exception msg: "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server." I am trying to connect to a testdb on my ubuntu vps and I'm sure that I wrote the url, username, password correctly. I'd be glad if you help, thanks.
Steven Byrne (2 years ago)
Ah, this error is hard to track down because it is a general "something went wrong" error, this answer (http://stackoverflow.com/questions/6865538/solving-a-communications-link-failure-with-jdbc-and-mysql) does give some great information and approaches to solve this (one of the ways will work, it's just a matter of trying them all). I'd bet it has something to do with the connection string as mentioned towards the middle bottom of the answer (~205 upvotes for the answer I am talking about). Let me know if this doesn't work for or you run into any trouble, best of luck!
Harry Sax (2 years ago)
You could have connected in one line of code.
The String Driver MUST have the following chars: com.mysql.jdbc.Driver   where in "Driver" the character "d" is in UPPPERCASE.
Steven Byrne (2 years ago)
This method should still work, however if you'd like to try something different, take a look at this Q/A (the first answer) http://stackoverflow.com/questions/2839321/connect-java-to-a-mysql-database The second answer does show a good walk through on how to use JDBC and Driver manager if you'd like too
Harry Sax (2 years ago)
Yeah I am actually not getting any good results using this method. Just doesn't work at all.
Steven Byrne (2 years ago)
You are correct, the primary reason I did not is: 1) I felt this way looked easier from a learner's stand point (just an opinion, I could very well be wrong) 2) It leaves it open to be modularized later on I really should at some point re-do these as Driver Manager is getting old, if not depreciated already. The newer way would be to use DataSource
Vandel Jason Strypper (2 years ago)
24.196.52.166:3306 where is this come from ?
Steven Byrne (2 years ago)
Vandel Jason Strypper does it say access denied in the java code or when you're working with the Mysql server itself? I would suspect it is either: 1) the user was not setup with the permissions for what you are trying to do, 2) the user is not setup with rights to the database you are trying to work with, or 3) there was a problem creating the user, what are you using to manager your MYSQL server, do you have PHPMyAdmin or are you using the Mysql console?
Steven Byrne (2 years ago)
Vandel Jason Strypper for the host use LOCALHOST you shouldn't need the port either. if that gives you an error please copy and paste it here and I can help more
Vandel Jason Strypper (2 years ago)
oh and i even create a account for the mysql and it keep saying access denied too
Vandel Jason Strypper (2 years ago)
it keep saying error when i input the ipv4 i did install the MySQL so now how to get that number ?
Steven Byrne (2 years ago)
24.196.52.166 is my public IP address (my host) if you installed MySQL on your computer you would use: LOCALHOST or if you have someone hosting your database (like a server you pay for) they would have either a domain name (something l like mydomain.com) or a public IP address similar to mine above. The 3306 is a the port. You can think of IP addresses like house addresses and ports like their doors. You may have 1 address but data (or people) can go in and out of that house from different ports (doors)
Vandel Jason Strypper (2 years ago)
can u give me the source to create the account
Steven Byrne (2 years ago)
The SQL code would be: "GRANT ALL PRIVILEGES ON database.* TO 'username'@'%' IDENTIFIED BY 'password';" This will grant all rights on the specified database and all sub tables (that's what the * means) to the user "username" connecting from any host using the password "password"... The only problem I see is if you don't have a root (admin) user account that has permissions to create another user account this won't help you, you would need your host to give you a username/password or you would need to create one using the root account (which you set the name/password for when you install MySQL). Hope this helps!
blackcrern (2 years ago)
did you run into any SSL issues? when i run my code to search my database, i get an error that says SSL must be set to true or false
Steven Byrne (2 years ago)
Try using this: jdbc:mysql://HOST:3306/DATABASE?autoReconnect=true&useSSL=false as your connection string. As this answer notes (http://stackoverflow.com/questions/34189756/warning-about-ssl-connection-when-connecting-to-mysql-database). Depending on your setup you may want to use SSL (SSL is basically the difference between protecting what is send to the database or having it be public (no ssl)). You can think of it allot like a bus VS a private armored car, when you're on the bus anyone can access it for a quarter, however in a private armored car it would be very hard to get your data while it's inside, however once your data (passenger) gets out of the car it's anyone's game. I just don't want anyone to think SSL will encrypt your database, it doesn't it just makes sure it gets to the database safely (encrypted) If you run into any trouble just let me know, good luck!
blackcrern (2 years ago)
thats fine! any help is much appreciated. Thank you!
Steven Byrne (2 years ago)
blackcrern sure will, it will probably be some time tomorrow night if all goes to plan!
blackcrern (2 years ago)
appreciate the quick response! could go into detail about the connection string? (once off the phone) i found so many site online but no straight or consistent answer
Steven Byrne (2 years ago)
blackcrern that would be a security issue which you might get depending on your server settings. you'll just need to specify useSSL true or false in the connection stirng. I'm on my phone so I can't find it easily but if you Google for it you should be able to find it
Đạt Nguyễn (2 years ago)
Oh, you reply very fast. I've seen your video about my sql and deleted my cmt immediately. I use sql server 14 and when I use connector type for sql server 12 it does not work. Now, I'm using my sql and it's ok. Thank you
Steven Byrne (2 years ago)
Not a problem, glad it is working! Good luck!
Enginerd Sunio (2 years ago)
also see https://youtu.be/PY14Ily_-vI
RealEyes (2 years ago)
@ Class.forName(driver); it sais classnotfoundexception
Steven Byrne (2 years ago)
+pascalirinel I'm almost sure you have to add the Jar file to the library in Intelijj, try taking a look at this thread: http://stackoverflow.com/questions/6164950/i-cant-load-the-jdbc-driver-for-mysql
RealEyes (2 years ago)
i use intelijj so i did project structure->module then added that bin file...which is the jar file
Steven Byrne (2 years ago)
That means something didn't work with importing the JAR file; basically its saying it can't find the jar file; did you include it in your external jars?
RealEyes (2 years ago)
man is that your ip address ? if it is your ip address then /databse is not required, no ? you do not give a lot of details while explaining...I mean for localhost what should we use ? you just present your situation
Steven Byrne (2 years ago)
That is correct, that is my IP and /database is not required. The reason I used it is it saves me from having to later tell MySQL which database I want to connect to. For localhost you need to have MySQL installed and running, from there everything would be the same (assuming you have a database created). This is just a video showing how to use the MySQL connector for Java and learn some programmatic syntax for it. It assumes you already have or know how to use a MySQL server (physical server operations) and a basic understanding of Java. If you don't you should look at a few entry MySQL videos and or Java tutorials; there are also plenty of MySQL hosts out there that will handle the networking and server administration side of things for you (like installing MySQL)
sandeep sah (2 years ago)
if there is another application need except ecclipse for using this code please reply as soon as possible
Steven Byrne (2 years ago)
+Steve Burrus I may have miss understood the question, there are tons of IDEs like eclipse or netbeans and even a few different connectors, no matter what you use though you will need those three components in one form or another. so you do need those 3 things, but they don't have to be the same ones I use to work
Steve Burrus (2 years ago)
Well tjhere IS the Netbeans IDE if yo u wanna use that. I suppose though that most people use the Eclipse IDE for some reason.
Steven Byrne (2 years ago)
There is no other application, what you will need it: 1) Eclipse (which should install the Java JDK, if you didn't do the full Eclipse install you'll need to make sure you have the Java JDK). 2) The Java Connector (Downloaded at: https://www.mysql.com/products/connector/ 3) Import the connector Jar as shown in the video Try taking a look at this for the JNI error: http://stackoverflow.com/questions/28922512/how-to-resolve-this-jni-error-when-trying-to-run-lwjgl-hello-world
sandeep sah (2 years ago)
i m executing same code i m gettting this error. a JNI error has occured please check installation and a java exception has occured
Sanae Kochiya (3 years ago)
Please use gists on gist.github.com (or search github gist)
Sanae Kochiya (3 years ago)
It makes it easy for others to access the code
mushinbujin (3 years ago)
Good: I successfully incorporated the Connector .jar into my project, otherwise it would complain about jdbc not being recognized. I have the correct IP address, otherwise it would tell me that no packets were received. Bad: The exception says "java.sql.SQLException: Access denied for user 'quser'" (etc.). So ultimately it's not connecting. I don't see a problem with the username, password or database name, but I tried getting each of them wrong and it didn't change the error message. So I'm not sure precisely what the problem is. Suggestions? By the way, I ended up using a MySQL database on an actual webhost. I also found out that you can install MySQL on Vista but you have to disable the User Account Security thingy before the install takes place.
mushinbujin (3 years ago)
+Steven Byrne I'm on Skype any time you're available. Also, my email is [email protected] if you want to contact me that way.
mushinbujin (3 years ago)
Ok, that's fine. Skype is: kingofchieves That would be great because I'm feeling pretty stumped right now.
Steven Byrne (3 years ago)
Yes, I'm sure we can set something up, would skype work? I work allot, and I won't be home tonight until 8PM US/Canada central time. Other days work for me though too
mushinbujin (3 years ago)
It's called HelioHost. They allow you to use a lot of different languages with less severe restrictions than some other hosts. Also, I checked and they DO NOT allow SSH. That is one thing they've had major security problems with. The odd thing is, the last time I tried to create a user for the database I'm using, I did not see a permission anywhere that just said "read" or "write." It could be that they're using an entirely different system. Would real-time chat be possible? Because I feel like we could get this worked out more quickly that way.
Steven Byrne (3 years ago)
What host are you using, I am looking here and I see the problem is almost surely permissions within the database, but I don't know how to change from other host companies. You might be able to use PHP my Admin, but I know on host gator I have to setup my accounts outside of PHPmyAdmin 
Ryan Moore (3 years ago)
I would love to get some extra help with this. I'm using NetBeans and so far it seems to be working, but I'm not a hundred percent sure how I would set up my own SQL database (or find one) to access with this code.
Ryan Moore (3 years ago)
Great, thanks! I'll check it out now.
Steven Byrne (3 years ago)
If you are still interested I did make a brief walk through here: https://www.youtube.com/watch?v=Nj76fBhfCxE&list=PLP63X8dYTuaJTAMBZUHScyUCsJVPjSQgJ
Ryan Moore (3 years ago)
+Steven Byrne Thanks! I will definitely check it out. I really appreciate beginning-to-end tutorials like The Java Hub, which even discusses setting up the whole environment and everything. That way, nothing is left out. Anyway, I'll watch these videos and see if they help.
Steven Byrne (3 years ago)
+Ryan Moore Great question, there are some amazing videos I can point you to, and due to the high request I probably make a video on it later. It is a long process but not very hard, here's some links to videos explaining how to set one up. https://www.youtube.com/watch?v=O4xXzTIcnDE & https://www.youtube.com/watch?v=-cHS4HoEFV8
Bac Dam (3 years ago)
Does MySQL get packed with the program when I compile the entire program?
Steven Byrne (3 years ago)
In general it should, in C# it doesn't always work. in Java it normally does and in Python I've never had an issue with it. in short, yes it's suppose to but sometime it does have an error so always test before releasing a program
Mehdi Melouah (3 years ago)
simple, clear. great work man
BANGANIRIKI FIDELE (3 years ago)
Of course!
BANGANIRIKI FIDELE (3 years ago)
Nice!
Steven Byrne (3 years ago)
+BANGANIRIKI FIDELE Thank you, any other videos you would like to see?
prasiprassi (3 years ago)
Thank you a lot! Best tutorial i have watched so far.
Steven Byrne (3 years ago)
Thank you! Let me know if there are any other videos / tutorials you'd like to see
Carlos Vizcaino (3 years ago)
Steven I am getting this error: No suitable driver found for jdbc:oracle:thin:@oracle.cise.ufl.edu:1521:orcl The url  for the data base is oracle.cise.ufl.edu. The port is 1521 Db name is orcl I have follow every step of your instruction. Thanks in advance (Great Video).
Steven Byrne (3 years ago)
+Steven Byrne Try using the following line of code, and see if that works, change "YOURIP_OR_HOST" to whatever your host is, which should be an IP address, or a localhost. If this does not work, please send what code you're using where you are getting the error (Removing passwords and usernames of course) and I can be of more help. String driver = "com.mysql.jdbc.Driver";  jdbc:mysql://YOURIP_OR_HOST:1521/orcl Good luck!
Steven Byrne (3 years ago)
So what that error is saying is the driver I had you install isnt being recognized. You can try reinstalling it, re-adding It to eclipse in the add external jars, and make sure you spelt everything right whe you declared your driver with the jdbc. Would you like a copy/paste for declaring the driver?
mathos (4 years ago)
tinke you steven
Ariel Rosario (4 years ago)
Hello how i can update a photo in SQLITE???????? if i select a photo and i need update for other  tell me please! 

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.