2 weixin 39701793 weixin_39701793 于 2017.09.06 17:46 提问

树莓派中安装的sqlite数据库,通过jdbc连接失败

代码相同,在windows平台运行可以通过,在树莓派中可以编译但运行报错,是不是因为arm板的原因
代码如下:
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: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.(CoreConnection.java:66)
at org.sqlite.jdbc3.JDBC3Connection.(JDBC3Connection.java:21)
at org.sqlite.jdbc4.JDBC4Connection.(JDBC4Connection.java:23)
at org.sqlite.SQLiteConnection.(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个回答

oyljerry
oyljerry   Ds   Rxr 2017.09.06 21:29

jdbc的数据库引擎在树莓派上没有。

weixin_39701793
weixin_39701793 你说的是jdbc驱动么?有的啊
3 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片