I am working on the connection of MySQL with Java.
I understand this is a tested practise because I see many file applications about it.
I have obtained the files:
LoadDriver.class
MakeConnection.class
below from the Connnector J 5.1 documentation.
The files are pasted in the jdk1.8.0_71 /bin directory en succesfully compiled into *.java files.
The mysql-connector-java-5.1.44-bin.jar file from the ConnectorJ5.1 documentation was also pasted in the jdk1.8.0_71 /bin directory.
The first file is the driver loader.
The second file is de connection maker
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
// Notice, do not import com.mysql.jdbc.*
// or you will have problems!
public class LoadDriver {
public static void main(String[] args) {
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MakeConnection {
public static void main(String[] args) {
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + "user=shorty@localhost&password=asdfgh456");
// Do something with the Connection
System.out.println("Connected to database");
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
}
SQLExeption: No suitable driver found for jdbc:mysql://localhost:3306/user=shorty@localhost&password=asdfgh456
SQLstate: 00001
VenderError: 0
This error above shows.
The files were entered at the commandline, with administrator privelige.
shorty@localhost&password=asdfgh456 is a tested user with password.
I hope you can point out the mistake I make, or any syntax error.
Hope to behearing from you soon.
Signing, best regards,
W.M.de Korte
info@wikowebsites.nl
I understand this is a tested practise because I see many file applications about it.
I have obtained the files:
LoadDriver.class
MakeConnection.class
below from the Connnector J 5.1 documentation.
The files are pasted in the jdk1.8.0_71 /bin directory en succesfully compiled into *.java files.
The mysql-connector-java-5.1.44-bin.jar file from the ConnectorJ5.1 documentation was also pasted in the jdk1.8.0_71 /bin directory.
The first file is the driver loader.
The second file is de connection maker
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
// Notice, do not import com.mysql.jdbc.*
// or you will have problems!
public class LoadDriver {
public static void main(String[] args) {
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MakeConnection {
public static void main(String[] args) {
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + "user=shorty@localhost&password=asdfgh456");
// Do something with the Connection
System.out.println("Connected to database");
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
}
SQLExeption: No suitable driver found for jdbc:mysql://localhost:3306/user=shorty@localhost&password=asdfgh456
SQLstate: 00001
VenderError: 0
This error above shows.
The files were entered at the commandline, with administrator privelige.
shorty@localhost&password=asdfgh456 is a tested user with password.
I hope you can point out the mistake I make, or any syntax error.
Hope to behearing from you soon.
Signing, best regards,
W.M.de Korte
info@wikowebsites.nl