JdbcRowSet无法识别MariaDB驱动程序

时间:2016-11-07 12:02:26

标签: java maven jdbc mariadb rowset

在项目的同一个包下,我有两个类。这些类是JDBC练习的一部分。我使用 MariaDB 10.1.14

的Class1

String jdbcUrl = "jdbc:mariadb://localhost:3306/test";
String uName = "root";
String pWord = "admin";
try{
    Connection connection = DriverManager.getConnection(jdbcUrl, uName, pWord);
    System.out.println(connection.isValid(100));
}catch(SQLException e){
    e.printStackTrace();
}

输出true

的Class2

String url = "jdbc://mariadb://localhost:3306/test";
String user = "root";
String pass = "admin";

try(JdbcRowSet rowSet = RowSetProvider.newFactory().createJdbcRowSet()){
    String query = "SELECT * FROM employee";
    rowSet.setCommand(query);
    rowSet.setUrl(url);
    rowSet.setUsername(user);
    rowSet.setPassword(pass);
    rowSet.execute();

    while(rowSet.next()){
        System.out.println(rowSet.getString(1));
    }
} catch (SQLException e) {
    e.printStackTrace();
}

输出

java.sql.SQLException: No suitable driver found for jdbc://mariadb://localhost:3306/test
    at java.sql.DriverManager.getConnection(DriverManager.java:689)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at com.sun.rowset.JdbcRowSetImpl.connect(JdbcRowSetImpl.java:643)
    at com.sun.rowset.JdbcRowSetImpl.prepare(JdbcRowSetImpl.java:654)
    at com.sun.rowset.JdbcRowSetImpl.execute(JdbcRowSetImpl.java:556)
    at com.my.project.demotwo.jdbc.RowSet001.main(RowSet001.java:21)

pom.xml 具有MariaDB的依赖关系。

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
    <dependency>
        <groupId>org.mariadb.jdbc</groupId>
        <artifactId>mariadb-java-client</artifactId>
        <version>1.1.7</version>
    </dependency>
</dependencies>

我试着四处寻找问题。但是,大多数人似乎用DriverManager报告。

有没有人遇到RowSet的问题?

1 个答案:

答案 0 :(得分:2)

您在连接字符串中使用jdbc://mariadb://而不是jdbc:mariadb://