soufrk soufrk - 1 month ago 23
Java Question

JdbcRowSet not recognizing MariaDB driver

Under the same package of a Project, I have two classes. The classes are part of JDBC exercises. I am using 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();
}


which outputs
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();
}


which outputs

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)


The pom.xml has dependencies for 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>


I tried looking around with the problem. But, most people seem to report it with
DriverManager
.

Has anyone had this problem with
RowSet
?

Answer

You are using jdbc://mariadb:// instead of jdbc:mariadb:// in the connection string.