注册 登录
编程论坛 SQLite论坛

在树莓派安装的sqlite,使用jdbc连接不上

wwffjj 发布于 2017-09-06 17:03, 3667 次点击
代码如下:
import java.sql.*;
import org.sqlite.JDBC;
public class Demo
{
    public static void main(String[] args) {
        try
        {
         Class.forName("org.sqlite.JDBC");      
         Connection conn = DriverManager.getConnection("jdbc:sqlite:D:\\bmdb.db");  
         Statement stat = conn.createStatement();         
         //stat.executeUpdate( "create table table1(name varchar(64), age int);" );   
//         stat.executeUpdate( "insert into item values(1,'a',1,'a',1);" );
//         stat.executeUpdate( "insert into item values(2,'b',2,'b',2);" );
//         stat.executeUpdate( "insert into item values(3,'c',3,'c',3);" );
 
         ResultSet rs = stat.executeQuery("select * from item;");  

         while (rs.next()) {

             System.out.print("i_name = " + rs.getString("i_name") + " ");
             System.out.println("age = " + rs.getString("i_id"));
         }
         rs.close();
        conn.close();
        }
        catch( Exception e )
        {
         e.printStackTrace ( );
        }
    }
}


运行结果:
java.sql.SQLException: Error opening connection
        at org.sqlite.core.CoreConnection.open(CoreConnection.java:140)
        at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:66)
        at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:21)
        at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:23)
        at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:45)
        at org.sqlite.JDBC.createConnection(JDBC.java:114)
        at org.sqlite.JDBC.connect(JDBC.java:88)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:270)
        at Demo.main(Demo.java:9)
Caused by: java.lang.Exception: No native library is found for os.name=Linux and os.arch=arm
        at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:284)
        at org.sqlite.SQLiteJDBCLoader.initialize(SQLiteJDBCLoader.java:65)
        at org.sqlite.core.NativeDB.load(NativeDB.java:53)
        at org.sqlite.core.CoreConnection.open(CoreConnection.java:136)
        ... 9 more
1 回复
#2
wwffjj2017-09-06 17:15
代码是在windows上运行的代码,在windows上的sqlite可以运行成功,在树莓派中报错
1