当前位置: 首页 > 知识库问答 >
问题:

没有找到适合jdbc的驱动程序:mariadb://127.0.0.1:3306/mydb?user=root

章越
2023-03-14

当我试图连接到我的数据库时,我收到了这条消息。这是一个使用Eclipse和MariaDB完成的Web应用程序。

package login.registration;

import java.sql.*;

public class MyConnectionProvider {

    private static Connection con = null;

    public static Connection dbConn() throws SQLException {

        // Connessione

        try {

            Class.forName("org.mariadb.jdbc.Driver");

        } catch (Exception e) {

            System.err.println(e.getMessage());

        } // fine try/catch

        con = DriverManager.getConnection("jdbc:mariadb://127.0.0.1:3306/mydb?user=root"); // aaa è il nome del DB

        return con;
    }

}

我已经把MySQL连接器java到项目库(项目是一个新的动态web项目)和MariaDB java客户端库。这里是我调用dbConn()的地方:

package login.registration;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class UtenteDAOImpl implements UtenteDAO {

    static Connection con;
    static Statement st;
    static ResultSet rs;

    @Override
    public int insertUtente(Utente user) {

        int status = 0;

        try {
            con = MyConnectionProvider.dbConn();
            st = con.createStatement();
            String sql = "INSERT INTO utenti (username,firstname,lastname,password,password2,email) VALUES ('"
                    + user.getUsername() + "','" + user.getFirstname() + "','"
                    + user.getLastname() + "','" + user.getPassword() + "','" + user.getPassword2() + "','"
                    + user.getEmail() + "')";
            rs = st.executeQuery(sql);
            System.out.println(rs);
            con.close();
            status = 1;

        } catch (Exception e) {

            System.out.println(e.getMessage());
        }

        return status;
    }

    @Override
    public Utente getUtente(String username, String password) {

        Utente user = new Utente();
        try {

            con = MyConnectionProvider.dbConn();
            st=con.createStatement();
            String sql = "SELECT * FROM UTENTI where username = " + username + " and password = " + password;
            rs = st.executeQuery(sql);
            while(rs.next()) {
                user.setUsername(rs.getString(1));
                user.setFirstname(rs.getString(2));
                user.setLastname(rs.getString(3));
                user.setPassword(rs.getString(4));
                user.setPassword2(rs.getString(5));
                user.setEmail(rs.getString(6));
            }
            con.close();

        } catch (Exception e) {

            System.out.println(e.getMessage());
        }

        return user;
    }

}

我用XAMPP连接了我的数据库,启动我的web应用程序的服务器是Tomcat 9.0。或多或少,我关注了这个应用的整个构建过程,观看了这个视频(如果你需要更多信息):https://www.youtube.com/watch?v=7bl8UrkYbaU

所以如何解决这个问题?提前感谢您的回复!!!

共有1个答案

盖弘毅
2023-03-14

打算mysql连接器使用MariaDB连接器/J. jar从下面的地址。

https://mariadb.com/downloads/#connectors

 类似资料: