root@debian:~# more SQLiteExample.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SQLiteExample {
public static void main(String[] args) {
// SQLite connection string
String url = "jdbc:sqlite:sample.db";
// SQL statement for creating a new table
String createTableSQL = "CREATE TABLE IF NOT EXISTS users ("
+ "id integer PRIMARY KEY, "
+ "name text NOT NULL, "
+ "email text NOT NULL UNIQUE);";
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
// Create a new table if it does not exist
stmt.execute(createTableSQL);
// Insert data into the users table
String insertSQL = "INSERT INTO users(name, email) VALUES ('Alice', 'alice@example.com')";
stmt.execute(insertSQL);
insertSQL = "INSERT INTO users(name, email) VALUES ('Bob', 'bob@example.com')";
stmt.execute(insertSQL);
// Query the users table
String selectSQL = "SELECT * FROM users";
ResultSet rs = stmt.executeQuery(selectSQL);
// Loop through the result set and print each row
while (rs.next()) {
System.out.println("ID: " + rs.getInt("id"));
System.out.println("Name: " + rs.getString("name"));
System.out.println("Email: " + rs.getString("email"));
System.out.println("-----------------------");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
root@debian:~# javac SQLiteExample.java
root@debian:~# java SQLiteExample -cp /usr/share/java/sqlite-jdbc.jar
No suitable driver found for jdbc:sqlite:sample.db
root@debian:~# ls /usr/share/java/sqlite-jdbc.jar
/usr/share/java/sqlite-jdbc.jar
以上程序,哪里错了,为什么不能运行成功?sqlite,jdbc已经成功安装了的,就在/usr/share/java目录下。
--
FROM 183.161.82.*