java—更新到mariadb的连接详细信息后,系统抛出classnotfoundexception

bfrts1fy  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(246)

我的网络托管公司建议我将“mysql jdbc connection”的详细信息改为“mariadb”,如下所示 getDBConnection() . 我已经下载了mariadb jar[ mariadb-java-client-1.7.4.jar ]兼容jdk1.7,并将jar添加到项目中。删除了现有的mysql jar[ mysql-connector-java-5.1.40-bin.jar ]避免任何冲突。清理并构建解决方案,然后重新启动tomcat服务器。提交数据时系统仍抛出以下错误。同时在这里调试时,我在这里接收到null connection = SoccerUtils.getDBConnection(); preparedStatement1 = connection.prepareStatement("insert into mydatabase.registeruser values(default,?,?,?,?,?,?,?,?,?,?,?)",Statement.RETURN_GENERATED_KEYS); 知道为什么仍然抛出classnotfoundexception:com.mysql.jdbc.driver吗?

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Oct 15, 2018 10:53:57 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [RegisterServlet] in context with path [/MyFirstJavaTest] threw exception
java.lang.NullPointerException
    at com.myfirstjavatest.pkg.RegisterServlet.addPlayer(RegisterServlet.java:134)
    at com.myfirstjavatest.pkg.RegisterServlet.doPost(RegisterServlet.java:110)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
//Code below:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

    public static Connection getDBConnection() {
        String url = "jdbc:mariadb://localhost:3307/";          
        String dbName = "mydatabase";       
        String driver = "org.mariadb.jdbc.Driver";      
        String userName = "root";       
        String password = "mypassword";     

        Connection conn = null;
        try {
            Class.forName(driver).newInstance();
            conn = DriverManager
                    .getConnection(url + dbName, userName, password);

        } catch (Exception e) {
            System.out.println(e);
        } finally {
        }
        return conn;
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题