I installed MySQL (latest update). I need to code to create and establish a connection to SQL DB & amp; manage the database (using SELECT, INSERT, CREATE).
I did everything, but could not create a connection. I also installed the MySQL / J connector, I just extracted the package .zipto the folder and added the path to the folder in Variables).
Can someone say wat means URL in the line below?
Connection connection = DriverManager.getConnection(url, username, password);
I tried this:
String url = "jdbc:odbc:sqlserver://localhost:3306/myfirstdb";
Connection con = DriverManager.getConnection(url, "root", "1234");
But it does not work. I can not understand the term "URL". Can someone explain the meaning of "url" and "wat" must be done to connect to the SQL server with Java.
Update:
This is the complete code. He still cannot connect.
import java.sql.*;
public class TestDriver {
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//This s wat actually i did for connection
System.out.println("Driver Loaded Succesfully");
}
catch (Exception e){
System.out.println("Unable to Load Driver!!!");
}
try {
Class.forName(com.mysql.jdbc.Driver"); // initialise the driver
String url ="jdbc:mysql://localhost:3306/myfirstdb";
Connection con = DriverManager.getConnection(url, "root", "1234");
System.out.println("connection Established");
}
catch(Exception e) {
System.out.println("Couldnt get connection");
}
}
}
Can you say that wat is the goal of connecting MySQL Connector / J?
user405398