• Monday , 26 June 2017

Java Tutorial 20 : Connect to MySQL Database

Code Canyon



Please Rate, Comment and Subscribe. http://creativitytuts.org.

source

3d Ocean

Related Posts

47 Comments

  1. Archievald Quiambao
    April 21, 2017 at 14:41

    Clear instructions

  2. itsthecrazytom
    April 21, 2017 at 14:41

    Good tutorial, helped me a lot, many thanks!

  3. Md Ashikul
    April 21, 2017 at 14:41

    good tutorial. Thank's

  4. Adam Botha
    April 21, 2017 at 14:41

    Thank you so much good sir

  5. SoFPy FuD
    April 21, 2017 at 14:41

    great video, thumbs up

  6. Bruno León
    April 21, 2017 at 14:41

    Dude, im self-learning managing DB, this video helps me a lot, tons of thxnks 🙂

  7. Elfin forest
    April 21, 2017 at 14:41

    Thanks Man

  8. jin5632
    April 21, 2017 at 14:41

    Best tutorial out there. Simple and easy to learn, big like. Thanks man

  9. Hidden
    April 21, 2017 at 14:41

    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

  10. _Muhammad Aqib_
    April 21, 2017 at 14:41

    Sir can u tell me how to insert and update and delete data from mysql db using jframe in java

  11. Abdullah Amir
    April 21, 2017 at 14:41

    plese can you tell me what is root" ",

  12. NK.
    April 21, 2017 at 14:41

    Thank you sooooo much

  13. blackcrern
    April 21, 2017 at 14:41

    what if you cant get to phpmyadmin

  14. Sanz Imagery
    April 21, 2017 at 14:41

    thank you … (y)

  15. Surender Singh
    April 21, 2017 at 14:41

    it was great help…

  16. Paritosh Bhattarai
    April 21, 2017 at 14:41

    it was really really helpful thanks a ton

  17. Thuy Pham
    April 21, 2017 at 14:41

    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?

  18. Aypee Sodinga
    April 21, 2017 at 14:41

    Thank you bra, your the best!!!!

  19. Igor Lemos
    April 21, 2017 at 14:41

    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();
    }

  20. Dieter Wittgens
    April 21, 2017 at 14:41

    Thank you so much! This was the only tutorial that actually explained what to do.

  21. HeXa _N3TC0D3
    April 21, 2017 at 14:41

    thx you helped a lot (Y)

  22. Osiris Robledo
    April 21, 2017 at 14:41

    Thank you!!

  23. GuidedPirate
    April 21, 2017 at 14:41

    Your a genius thank you! Keep up the good work

  24. Christian Spies
    April 21, 2017 at 14:41

    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!

  25. sidahmed mohamed
    April 21, 2017 at 14:41

    Thank you very much

  26. Davi Oliveira
    April 21, 2017 at 14:41

    good tutorial! I have a question, Does my client need to install MySQL in his computer to use a program like that?

  27. Sourav Das
    April 21, 2017 at 14:41

    how to write data in the database..?

  28. JustSome Dude
    April 21, 2017 at 14:41

    Thank you Naveed

  29. Shamez Rajan
    April 21, 2017 at 14:41

    great tutorial
    thanks

  30. lesley dianne Bargamento
    April 21, 2017 at 14:41

    Thanks 🙂 it was so helpful !

  31. ScottyM
    April 21, 2017 at 14:41

    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

  32. LET us CODE
    April 21, 2017 at 14:41

    thank u sooo. muchhh

  33. amir46824681
    April 21, 2017 at 14:41

    It gives me an error could you please guide me?

  34. George Recinos
    April 21, 2017 at 14:41

    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 🙂

  35. Fatima zahra Ritouni
    April 21, 2017 at 14:41

    Thank you so much 🙂 it's so helpful ,

  36. graf gggg
    April 21, 2017 at 14:41

    thanks mate

  37. Philip Anderson
    April 21, 2017 at 14:41

    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.

  38. DROGON
    April 21, 2017 at 14:41

    Thank you very much 🙂

  39. Deepak Kumar
    April 21, 2017 at 14:41

    Thank you so much…

  40. Sebastian Kupis
    April 21, 2017 at 14:41

    Work fine on Ubuntu with Eclipse. Thanks a lot.

  41. Álvaro José Ruiz López
    April 21, 2017 at 14:41

    Great Tutorial, thanks u so much !!!

  42. patel bhavik
    April 21, 2017 at 14:41

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

  43. Ali yasar E
    April 21, 2017 at 14:41

    gg wp

  44. Erfan Ahmed
    April 21, 2017 at 14:41

    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");

  45. Thikthak Shrestha
    April 21, 2017 at 14:41

    Awesome tutor

  46. B100dyPhr34k
    April 21, 2017 at 14:41

    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();
    }
    }
    }

  47. Z O M B O Z O
    April 21, 2017 at 14:41

    thanks a lot man, so helped for me 😀

Leave A Comment

You must be logged in to post a comment.