标题:在树莓派安装的sqlite,使用jdbc连接不上
只看楼主
wwffjj
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-9-6
 问题点数:0 回复次数:1 
在树莓派安装的sqlite,使用jdbc连接不上
代码如下:
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
搜索更多相关主题的帖子: sqlite jdbc java sql item 
2017-09-06 17:03
wwffjj
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-9-6
得分:0 
代码是在windows上运行的代码,在windows上的sqlite可以运行成功,在树莓派中报错
2017-09-06 17:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-480522-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.048784 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved