我有Windows XP中的DataBase MariaDB的Netbean IDE 7.3.1。 但沒有連接......這 類代碼ConexionDB.java:如何將java與mariadb連接到windows?
import java.sql.Connection;
import java.sql.DriverManager;
import javax.naming.NamingException;
public class ConexionDB {
private String enlace;
private String controlador;
private String error;
private String usuario;
private String contrasenia;
public ConexionDB(){
this.enlace = "jdbc:mariadb://localhost:3306/test";
this.controlador = "org.mariadb.jdbc.Driver";
this.error = " ";
this.usuario = "root";
this.contrasenia = "mariadb";
}
public Connection abrirConexion() throws NamingException{
try{
Class.forName(getEnlace()).newInstance();
return DriverManager.getConnection(getEnlace(), getUsuario(), getContrasenia());
}catch (Exception e){
setError(e.getMessage());
System.out.println("error al conectar " + getError());
}
return null;
}
public void cerrarConexion(Connection salida){
try{
salida.close();
}catch(Exception e){
setError(e.getMessage());
System.out.println("error al conectar " + getError());
}
}
而這種代碼Main.Java
import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.NamingException;
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) throws NamingException, SQLException{
ConexionDB instanciaDB = new ConexionDB();
Connection actualDB;
actualDB = instanciaDB.abrirConexion();
if(actualDB != null)
JOptionPane.showMessageDialog(null, "Conexion Realiazada Correctamete!");
}
}
總是我已經在輸出相同的錯誤: 錯誤人conectar JDBC :mariadb:// localhost:3306/test [error to connect jdbc:mariadb:// localhost:3306/test] 在這個問題中的任何想法! Grettings。