求助:关于Java连接SQLite遇到问题,希望懂的大神帮忙
根据网上的教程,用NetBeans开发java,在项目中导入sqlite-jdbc.jar包,然后希望连接sqlite数据库。但是一直报错。找了很久没找到原因,希望懂的大神帮忙,在线急等!!谢谢!附(程序代码):
package sqlitetest;
import java.sql.*;
import org.sqlite.JDBC;
public class TestSQLite
{
public static void main(String[] args)
{
try
{
//连接SQLite的JDBC
Class.forName("org.sqlite.JDBC");
//建立一个数据库名zieckey.db的连接,如果不存在就在当前目录下创建之
Connection conn = DriverManager.getConnection("jdbc:sqlite:d:/zieckey.db");
Statement stat = conn.createStatement();
stat.executeUpdate( "create table tbl1(name varchar(20), salary int);" );//创建一个表,两列
stat.executeUpdate( "insert into tbl1 values('ZhangSan',8000);" ); //插入数据
stat.executeUpdate( "insert into tbl1 values('LiSi',7800);" );
stat.executeUpdate( "insert into tbl1 values('WangWu',5800);" );
stat.executeUpdate( "insert into tbl1 values('ZhaoLiu',9100);" );
ResultSet rs = stat.executeQuery("select * from tbl1;"); //查询数据
while (rs.next()) { //将查询到的数据打印出来
System.out.print("name = " + rs.getString("name") + " "); //列属性一
System.out.println("salary = " + rs.getString("salary")); //列属性二
}
rs.close();
conn.close(); //结束数据库的连接
}
catch( Exception e )
{
e.printStackTrace ( );
}
}
}
另附(报错提示):
run:
java.lang.UnsatisfiedLinkError: C:\Users\Mike\AppData\Local\Temp\sqlite-3.8.11.2-7297b15e-f8ad-47d3-bec9-ba3792ed5fac-sqlitejdbc.dll: 拒绝访问。
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.sqlite.core.NativeDB._open(Ljava/lang/String;I)V
at org.sqlite.core.NativeDB._open(Native Method)
at org.sqlite.core.DB.open(DB.java:161)
at org.sqlite.core.CoreConnection.open(CoreConnection.java:220)
at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:76)
at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:24)
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 sqlitetest.TestSQLite.main(TestSQLite.java:18)
C:\Users\Mike\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
构建失败 (总时间: 1 秒)