Connecting to a mySQL database using Java -


That's why I have just started learning about the database this week and from what I want to be able to do One of my my SQL database that I created using Java I did some research and I have tried to find the right way to do this, I can not understand how. Here is my code:

  import java.sql.Connection; Import java.sql.DriverManager; Import java.sql.SQLException; Public Seven Menu {Public Zero Menu () {connection Conn; String url = "jdbc: mysql: // localhost: 3306"; String dbnm = "gym"; String driver = "com.mysql.jdbc.Driver"; String user name = "root"; String password = "password"; Try {class.forName (driver). NewestInstance (); Conn = DriverManager.getConnection (url + dbn name, username, password); System.out.println ("Connect to database"); Conn.close (); System.out.println ("Disconnected from database"); } Hold (exception e) {System.out.println ("no connection = ("); System.out.println (e.getMessage ());}}}  

problem now It is that every time I run this code, "no connection is there" (appears and then it says that there is an error: "com.mysql.jdbc.Driver". Can someone help me And can say what I am doing

Your error means that the jar in your library path Is not included in the com.mysql.jdbc.Driver category.

Paco does not need to change anything in its code. If you are running it through eclipse, you will see the Mysql-connector-java-xxx-bin.jar on your construction path (where xxx jar Version).


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -