Thank you so much. I use Neatbeans 8.1, and then I choose Libraries/Add Lib, I can see Mysql JDBC Driver ( it's avalable in lib to add), so I needn't download it. Is difference with 7.1.2 version?
If would it be possible to use a php config file, which holds the connection to your mysql db info, Then pass variable data from your java class to access the php script, thus effectively by passing the need to download the JDBC driver file and then add that to your server host file.
Great tutorial!聽 I've been trying do this for some time now.聽 Thanks to your tutorial I was able to connect to a database in Java.聽 I have an inquiry.聽 When I try to run the app from a command prompt using, "java Main" I get the following error: "Error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver".聽 I tried adding聽the "-classpath" argument, but that didn't solve the problem.聽 Can you please help?聽 Cheers 馃檪
I just want to thank you for this tutorial which worked for me! The only problem I had was my XAMPP did not work so I tried MAMP on my MAC. That did not work until I enabled, in MAMP PRO advanced settings, the 'allow access from network' tick box, after which the jdbc:mysql://localhost:3306/db string worked for me. After that the fields appeared straight away so many thanks for your help.
Hi, I have an issue here. I can access phpmyadmin on a server (using TCP/IP) using java but if the database on a UNIX server java can't establish connection using driverManagement class. what should i do in this case ??? need your help ….!!
ie. it works fine –> Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbName", "root", "pass");
but if database on a UNIX server connecting through SOCKET it does't work –> 聽 //connection = DriverManager.getConnection("jdbc:mysql://localhost", "user_name", "pass");
47 responses to “Java Tutorial 20 : Connect to MySQL Database”
Clear instructions
Good tutorial, helped me a lot, many thanks!
good tutorial. Thank's
Thank you so much good sir
great video, thumbs up
Dude, im self-learning managing DB, this video helps me a lot, tons of thxnks 馃檪
Thanks Man
Best tutorial out there. Simple and easy to learn, big like. Thanks man
Thank you so much .. you made my life a lot easier ..
but can you please tell me how do I insert and delete from the data base using java?
do I use the command "alter" ? and how the syntax would be?
I really really appreciate the work you've done <3
Sir can u tell me how to insert and update and delete data from mysql db using jframe in java
plese can you tell me what is root" ",
Thank you sooooo much
what if you cant get to phpmyadmin
thank you … (y)
it was great help…
it was really really helpful thanks a ton
Thank you so much. I use Neatbeans 8.1, and then I choose Libraries/Add Lib, I can see Mysql JDBC Driver ( it's avalable in lib to add), so I needn't download it. Is difference with 7.1.2 version?
Thank you bra, your the best!!!!
The code he uses (To make easier to check):
import java.sql.*;
public class DBConnect {
private Connection con;
private Statement st;
private ResultSet rs;
public DBConnect() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
st = con.createStatement();
} catch (Exception ex) {
System.out.println("Error: " + ex);
}
}
public void getData() {
try {
String query = "select * from persons";
rs = st.executeQuery(query);
System.out.println("Records from Database");
while (rs.next()) {
String name = rs.getString("name");
String age = rs.getString("age");
System.out.println("Name: " + name + " Age: " + age);
}
} catch(Exception ex) {
System.out.println(ex);
}
}
}
public class Main {
public static void main(String[] args) {
DBConnect connect = new DBConnect();
connect.getData();
}
Thank you so much! This was the only tutorial that actually explained what to do.
thx you helped a lot (Y)
Thank you!!
Your a genius thank you! Keep up the good work
Very good tutorial. Good teaching speed, logical setup, no useless things. Helped me in shortest time to make a start in Java + mySQL. Thanks a lot!
Thank you very much
good tutorial! I have a question, Does my client need to install MySQL in his computer to use a program like that?
how to write data in the database..?
Thank you Naveed
great tutorial
thanks
Thanks 馃檪 it was so helpful !
Hi I just watch your video and I was wondering,
If would it be possible to use a php config file, which holds the connection to your mysql db info, Then pass variable data from your java class to access the php script, thus effectively by passing the need to download the JDBC driver file and then add that to your server host file.
cheers
thank u sooo. muchhh
It gives me an error could you please guide me?
Great tutorial!聽 I've been trying do this for some time now.聽 Thanks to your tutorial I was able to connect to a database in Java.聽 I have an inquiry.聽 When I try to run the app from a command prompt using, "java Main" I get the following error: "Error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver".聽 I tried adding聽the "-classpath" argument, but that didn't solve the problem.聽 Can you please help?聽 Cheers 馃檪
Thank you so much 馃檪 it's so helpful ,
thanks mate
Hi
I just want to thank you for this tutorial which worked for me! The only problem I had was my XAMPP did not work so I tried MAMP on my MAC. That did not work until I enabled, in MAMP PRO advanced settings, the 'allow access from network' tick box, after which the jdbc:mysql://localhost:3306/db string worked for me. After that the fields appeared straight away so many thanks for your help.
Thank you very much 馃檪
Thank you so much…
Work fine on Ubuntu with Eclipse. Thanks a lot.
Great Tutorial, thanks u so much !!!
** END NESTED EXCEPTION **
Last packet sent to the server was 22 ms ago.
java.lang.NullPointerException
BUILD SUCCESSFUL (total time: 2 seconds)
plz help this error found
gg wp
Hi, I have an issue here. I can access phpmyadmin on a server (using TCP/IP) using java but if the database on a UNIX server java can't establish connection using driverManagement class. what should i do in this case ??? need your help ….!!
ie.
it works fine –>
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbName", "root", "pass");
but if database on a UNIX server connecting through SOCKET
it does't work
–>聽 //connection = DriverManager.getConnection("jdbc:mysql://localhost", "user_name", "pass");
Awesome tutor
When I run my code it doesn't connect the program is just stuck in some infinite loop, here is the code:
import java.sql.*;
public class Main
{
public static void main(String[] args)
{
String url = "jdbc:mysql://localhost:8080/";
String database_name = "test";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try
{
Class.forName(driver).newInstance();
System.out.println("Connecting…");
Connection connection = DriverManager.getConnection(url + database_name, userName, password);
System.out.println("Connected!");
System.out.println(connection.getClientInfo());
connection.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
thanks a lot man, so helped for me 馃榾