Java 1.8.0_60,MariaDB v10.0和mariadb-java-client 1.2.2,“找不到合适的驱动程序”

我试图找出为什么我无法连接到笔记本电脑上的mariadb. MariaDB安装了几个数据库,我可以使用HeidiSQL连接而没有问题.

我正在尝试将Java应用程序连接到数据库,但我得到:

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mysql
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)

我已经下载了“mariadb-java-client-1.2.2.jar”并将其添加到项目中.

我的数据库URI是:

jdbc:mysql://localhost:3306/mysql

我试过改变使用方法:

jdbc:mariadb://localhost:3306/mysql

结果相同.我之前在另一台PC上工作过,但我不知道它为什么不在笔记本电脑上工作?用户名和密码正确,与用于连接HeidiSQL的用户名和密码相同.

我试过两个:

Class.forName("com.mysql.jdbc.Driver");

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

注册图书馆然后我读到这些不是必需的….我错过了什么?

码:

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

public class clsDB {
//The name of this class    
    private static final String TAG = clsDB.class.toString();   
//Define database URL, user name and password
    private static final String SERVER_ADDR = "localhost";
//The database address on Windows development system    
    private static final String DB_URL = "jdbc:mariadb://" + SERVER_ADDR +  ":3306/mysql";
    private static final String USER_NAME = "root";
    private static final String PASSWORD = "RRCmcs2014";
//Database connection object    
    private Connection m_con = null;
/**
 * Class constructor    
 * @throws Exception 
 */
    public clsDB() throws Exception {
//Create connection to database     
        connect();
    }
/**
 * @param strMethod the method the error occurs in
 * @param strMsg the message to display
 */
    private void errorMsg(String strMethod, String strMsg) {
        System.out.println(TAG + "." + strMethod + ": " + strMsg);
    }
/**
 * Destructor
 */
    protected void finalize() throws Throwable {
        close();
    }
/**
 * Attempts to close database connection    
 * @throws SQLException 
 */
    public void close() throws SQLException {
        if ( m_con != null && m_con.isClosed() == false ) {
            m_con.close();
        }       
    }
/**
 * Commits any changes to the database  
 * @throws SQLException
 */
    public void commit() throws SQLException {
        if ( m_con != null && m_con.isClosed() == false ) {
            m_con.commit();
        }
    }
/**
 * Attempts to connect to database  
 * @throws Exception 
 */
    private void connect() throws Exception {
//Get a connection to the database
        m_con = (Connection)DriverManager.getConnection(DB_URL,     
                                                        USER_NAME, 
                                                        PASSWORD);
        if ( m_con == null ) {
            throw new Exception( "Cannot connect to database!" );
        }
//Disable auto-commit       
        m_con.setAutoCommit(false);
    }
/**
 * Performs SQL execute or update   
 * @param strSQL, the SQL statement to perform
 * @return If an insert was performed then the insert ID, 
 *         If an update then the number of effected rows
 */
    public long execute(String strSQL) throws SQLException {
        Statement st = null;
        long lngRC = 0;
        try{
            if ( m_con != null ) {
                if ( m_con.isClosed() == true ) {
                    try{
                        connect();
                    } catch( Exception ex ) {
                        errorMsg("query", ex.getMessage());
                    }
                }
                st = (Statement)m_con.createStatement();

                if ( (lngRC = (int)st.executeUpdate(strSQL,    Statement.RETURN_GENERATED_KEYS)) > 0 ) {
                    if ( strSQL.toUpperCase().startsWith("INSERT") == true ) {
                        ResultSet keys = st.getGeneratedKeys();

                        if ( keys != null ) {
                            keys.next();
                            lngRC = keys.getLong(1);
                        }
                    }                   
                    m_con.commit();
                }
            }
        } catch( SQLException ex ) {
            errorMsg("execute", ex.getMessage());
        } finally {
            if ( st != null ) {
                st.close();
            }
        }
        return lngRC;
    }       
/**
 * @return The database connection object
 */
    public Connection getConnection() {
        return m_con;
    }
/**
 * Performs SQL query   
 * @param strSQL, the SQL statement to perform
 * @return the result of the query
 */
    public ResultSet query(String strSQL) throws SQLException {
        Statement st = null;
        ResultSet rs = null;
        try{
            if ( m_con != null ) {
                if ( m_con.isClosed() == true ) {
                    try{
                        connect();
                    } catch( Exception ex ) {
                        errorMsg("query", ex.getMessage());
                    }
                }
                st = (Statement)m_con.createStatement();
                rs = st.executeQuery(strSQL);
            }
        } catch( SQLException ex ) {
            errorMsg("query", ex.getMessage());
        }
        return rs;
    }   
}

解决方法:

似乎Mariadb驱动程序1.2.2对org.slf4j.LoggerFactory有隐藏的依赖.

如果使用该命令,您实际上可以看到这一点

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

并查看生成的堆栈跟踪. JDBC 4及更高版本不需要该命令,但它对于跟踪JDBC驱动程序自动注册失败的原因很有用.

所以,你得到的堆栈跟踪是:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at org.mariadb.jdbc.Driver.<clinit>(Driver.java:71)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at testing.clsDB.connect(clsDB.java:65)
    at testing.clsDB.<init>(clsDB.java:26)
    at testing.SimpleTest.main(SimpleTest.java:7)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

这是一个错误,应该向MariaDB的供应商报告,因为他们在documentation中没有提到这个要求/依赖.

解决方法

目前,您的解决方案只是下载MariaDB driver 1.2.0.

原文地址:https://codeday.me/bug/20190609/1203139.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


安装开始...1.打开“https://dev.mysql.com/downloadsepo/yum/”下载Mysql源      将下载好的mysql源上传linux服务器 2.yumlocalinstallmysql80*#安装源 centos7中默认安装的是mariadb数据库,如果想要安装mysql,首先要移除mariadb;
安装Helm3#官网下载慢#wgethttps://get.helm.sh/helm-v3.5.4-linux-amd64.tar.gzwgethttp://qiniu.dev-share.top/helm-v3.5.4-linux-amd64.tar.gztar-zxvfhelm-v3.5.4-linux-amd64.tar.gzcplinux-amd64/helm/usr/local/bin#查看helmclient版本helmversion
通过Linux命令行启动用的指令:systemctlstartmariadb.service反馈:Failedtostartmariadb.service:Unitmariadb.servicenotfound.MariaDB简介MariaDB是MySQL的一个分支,MariaDB打算保持与MySQL的高度兼容性,确保具有库二进制奇偶校验的直接替换功能,以及与MySQLAPI和命令
InstallingMariaDBServer10.4TodeployMariaDBCommunityServer10.4onRHEL7orCentOS7,firstdownloadandusethe mariadb_repo_setup scripttoconfiguretheMariaDBrepositoriesforYUM:$sudoyuminstallwget$wgethttps://downloads.mariadb.com/
阅读目录一什么是存储引擎二mysql支持的存储引擎三使用存储引擎一什么是存储引擎mysql中建立的库--> 文件夹库中建立的表--> 文件现实生活中我们用来存储数据的文件有不同的类型,每种文件类型对应各自不同的处理机制:比如处理文本用txt类型,处理表格用excel,处理图片
1、安装MariaDB安装命令yum-yinstallmariadbmariadb-server安装完成MariaDB,首先启动MariaDBsystemctlstartmariadb设置开机启动systemctlenablemariadb[root@node1~]#systemctlenablemariadbCreatedsymlinkfrom/etc/systemd/system/multi-user.target.wants/m
Centos7.5 刚安装的mariadb数据库报错报错:ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(usingpassword:NO)原因一:没有启动数据库解决方法:systemctlstartmariadbsystemctlenablemariadb原因二:未知解决方法:[root@db01~]#
基于YUM安装的mariadb多实例.=================================================================1.yum安装mariadb-server包#yuminstallmariadb-server2.创建多实例对应的目录结构#mkdir/mysql/{3306,3307,3308}/{data,etc,socket,log,bin,pid}-pv#tree/mysql//mysql/
一、系统环境[root@localhost~]#cat/etcedhat-releaseCentOSLinuxrelease7.6.1810(Core)二、mysql安装#yuminstallmysqlmysql-servermysql-devel安装mysql-server失败,如下图:[root@localhost~]#yuminstallmysql-serverLoadedplugins:fastestmirrorLoadingm
数据库的选择两大点是:开源和跨平台,满足这三点MySQL、MongoDB和MariaDB。其中MariaDB是MySQL的分支,也是它的进阶产品,未来很有可能替代MySQL。与MySQL相比较,MariaDB更强的地方在于:Maria 存储引擎PBXT存储引擎XtraDB 存储引擎FederatedX 存储引擎更快的复制查询处理线
使用Navicat连接数据库时出现了 HostxxxisnotallowedtoconnecttothisMariaDbserver的情况。发现了是因为授权的问题,使得连接权限受阻。所以,只需要进入数据库中,给予其权限即可。具体解决代码如下:[root@localhost~]#mysql-uroot-pEnterpassword:#首先进入mys
1.临时表当绘画结束时,临时表会自动销毁,无法用showtables查看临时表。MariaDB[jason]>createtemporarytabletmp(prochar(30),citychar(30));QueryOK,0rowsaffected(0.01sec)MariaDB[jason]>insertintotmpvalues('shanghai','shanghai');QueryOK,1
为了看阳光我来到世上数据库介绍数据库是一个存放数据的仓库,目前市面上最流行的数据库大致氛围的两种,一种叫做关系型数据库,一种叫做非关系型数据库,而关系型数据库近期流行的即为mysql,mysql原本是一个开源的数据库后被oracle公司收购,开始进行服务收费,因此,市面上大多数免费
1,Linux上的mysql MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松
启动Mariadb前提需安装mariadb-server-安装mariadb-serveryuminstall-ymariadb-server-启动服务systemctlstartmariadb.service-添加到开机启动systemctlenablemariadb.service-安全设置,以及修改数据库管理员密码mysql_secure_installation-启
1、查看是否安装及可用安装:yumlist|grepmaria2、安装maria(依赖其他几个安装包):yuminstallmariadb-server.x86_64输入'y'继续安装直到安装结束3、检查是否安装:4、安装完后登录提示错误:mysql-uroot-p是由于安装完但是并未启动maria服务5、启动maria有以下几种方法:system
通过yum安装mariadb,并配置MySQL主从服务器主服务器:192.168.10.11从服务器:192.168.10.12#!/bin/bash#====================================================#Author:Mr.Song#CreateDate:2019-02-21#Description:autoconfigMySQLmaster&slave#=====================
实验:实现基于SSL加密的主从复制实验步骤:环境:三台主机,一台CA:200,一台master:150,一台slave:100平时都是在CA上帮用户生成私钥,在服务器上做的1CA,master,slave的证书相关文件mkdir/etc/my.cnf.d/sslcd/etc/my.cnf.d/sslopensslgenrsa2048>cakey.pemopensslreq-new-x509-k
MariaDB[db1]>select*fromstudent;+----+------+-----+--------+-------+|id|name|age|gender|phone|+----+------+-----+--------+-------+|1|a|20|m|119||2|b|20|m|120||3|c|20|m|110
过年了,在老家闲余时间想敲敲代码,发现在安装mariaDb的时候一直报错错误信息:Service‘MySQL’(MySQL)Faildtostart,Verifythatyouhavesuffcientprivilegestostartsystemservices.服务的MySQL(MySQL)启动错误,确认你有权限启动系统服务。记得多年前在使用sqlserver数