Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newer versions (>sqlite-jdbc-3.43) can't open example database "chinook.db" #1093

Open
hsbpl opened this issue Apr 11, 2024 · 1 comment
Open

Comments

@hsbpl
Copy link

hsbpl commented Apr 11, 2024

Describe the bug
A very common sqlite example database exists: chinook.db. It can be downloaded here.

Earlier versions of sqlite-jdbc allowed connecting to this database, e.g., sqlite-jdbc-3.36.0.3.jar works. Newer versions such as sqlite-jdbc-3.43.2.2.jar or sqlite-jdbc-3.45.2.0.jar result in an SQLException "No suitable driver found for jdbc:sqlite:chinook.db"

To Reproduce
Create IntelliJ Project, put chinook.db inside the project folder. Download sqlite-jdbc-3.45.2.0.jar, add it to the project's classpath. Build and execute the following code:

` public static void main(String[] args) {
Connection conn = null;
try {
String url = "jdbc:sqlite:chinook.db";
conn = DriverManager.getConnection(url); // This line fails

        System.out.println("Connection to SQLite has been established.");
    } catch (SQLException e) {
        System.out.println(e.getMessage());
    } finally {
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException ex) {
            System.out.println(ex.getMessage());
        }
    }
}`

Expected behavior
Database connection should be opened, instead "No suitable driver found for jdbc:sqlite:chinook.db". When switching inside this project to an older lib version, connection is successful.

Environment (please complete the following information):

  • OS: Windows 10
  • Java SDK 22
  • IntelliJ

Additional context
May be a chinook.db problem?

@neoxpert
Copy link

"No suitable driver found for" sounds more like a problem with the class path / module path / project setup. This is a default error message from within the DriverManager class. The DriverManager uses a simple ServiceLoader based mechanism to lookup all viable JDBC drivers and checks if one of the found drivers can handle the provided URL. If the error message get's thrown, no driver has been found on the class path, that can handle URLs of a certain pattern.

In a very basic Maven project consisting of the parts below, I cannot reproduce the issue. Tested with the versions you have mentioned and the latest release 3.46.0.0.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>test</groupId>
	<artifactId>test</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<dependencies>
		<dependency>
			<groupId>org.xerial</groupId>
			<artifactId>sqlite-jdbc</artifactId>
			<version>3.46.0.0</version>
		</dependency>
	</dependencies>
</project>

Test.java

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

public class Test {
  public static void main(String[] args) {
    String url = "jdbc:sqlite:chinook.db";

    try (Connection conn = DriverManager.getConnection(url)) {
      System.out.println("Connection to SQLite has been established.");

      try (PreparedStatement statement = conn.prepareStatement("SELECT COUNT(*) FROM ALBUMS");
          ResultSet result = statement.executeQuery()) {
        if (result.next()) {
          System.out.println("Got %d albums.".formatted(result.getInt(1)));
        }
      }
    } catch (SQLException e) {
      System.out.println(e.getMessage());
    }
  }
}
.
├── src
│   └── main
│         └── java
│               └── Test.java
├── chinook.db
└── pom.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants