java中怎么使用sqlite3.dll

bbb332 2011-12-02 10:20:19
sqlite3.dll中的声明是

int sqlite3_open(const char*, sqlite3**);

在c#中可以这样声明

[DllImport("sqlite3.dll", EntryPoint = "sqlite3_open",CallingConvention=CallingConvention.Cdecl)]
public static extern int sqlite3_open(string filename, out IntPtr db);

在delphi中声明是:

SQLite3_Open: function(dbname: PAnsiChar; var db: pointer): integer; cdecl;

我想知道在java中怎么使用?谢谢了
...全文
391 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
woshiguoenying 2014-01-21
  • 打赏
  • 举报
回复
好久的老帖子了,请问楼主解决了嘛? 告诉一下解决方式啊
liuhui168168 2011-12-07
  • 打赏
  • 举报
回复
在c#中可以这样声明
public static extern int sqlite3_open(string filename, out IntPtr db);
可以看出 IntPtr 是一个特殊的 整形数据,所以应对与Java里面的可以用int 来应对,所以后续的工作就好做了。


public interface JnaUseSqlite3Dll extends StdCallLibrary {
//加载动态链接库,把库dll文件默认放到系统C盘window目录下的system32文件夹下
JnaUseSqlite3Dll instance = (JnaUseSqlite3Dll)Native.loadLibrary("sqlite3", JnaUseSqlite3Dll.class);
//对应动态链接库中的方法, 要注意的是 这里的方法必须要和链接库(dll文件)对应的方法名一致
public int sqlite3_open(String filename, int db);//db

}


====================================
/**
* 工具类
* @author Administrator
*
*/
public class Sqlite3Util {
/**
* 得到一个jna实例,调用dll动态链接库,
* @return
*/
public static JnaUseSqlite3Dll getInstance() {
return JnaUseSqlite3Dll.instance;
}

/**
*
*
*/
public static int sqlite3_open(String filename) {

int returnNum = getInstance().sqlite3_open(filename, 0);
return returnNum;
}


public static void main(String[] args) {
String filename="xxxxx";
Sqlite3Util.sqlite3_open(filename);
}
}

楼主可以试试,看看这个是否对你有所帮助

karl1235 2011-12-06
  • 打赏
  • 举报
回复
友情帮顶,第一次见到sqlite.dll
bbb332 2011-12-06
  • 打赏
  • 举报
回复
还有没有知道呀?
dracularking 2011-12-02
  • 打赏
  • 举报
回复
正面寻求的话,不妨看看这个:
http://tvjody.iteye.com/blog/125643
休谱诺斯 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 inhibitory 的回复:]

为什么要使用sqlite.dll?
直接使用JDBC就可以访问sqlite数据库
[/Quote]
Inhibitory 2011-12-02
  • 打赏
  • 举报
回复
为什么要使用sqlite.dll?
直接使用JDBC就可以访问sqlite数据库
bbb332 2011-12-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 inhibitory 的回复:]

为什么要使用sqlite.dll?
直接使用JDBC就可以访问sqlite数据库
[/Quote]
我要使用别人的db,而且别人的db是经过加密的,只能调用它们封装的sqlite3.dll
Java下连接SQLite数据库 一、下载SQLite数据库的JDBC:http://www.zentus.com/sqlitejdbc/ 二、将下载到的包解压后得到jar包放到%JAVA_HOME%\lib下,并且将其添加到ClassPath系统环境变量。一定要保证在类路径ClassPath有该jar包,并且保证在JAVA库路径JAVA Library Path有本地库Native Library(\workspace\"Web应用"\WebRoot\WEB-INF\lib\下最好也要加入该jar包)。"SQLite.JDBCDriver"作为JDBC的驱动程序类名。连接JDBC的URL格式为jdbc:sqlite:/path。这里的path为指定到SQLite数据库文件的路径,例如: jdbc:sqlite://dirA/dirB/dbfile jdbc:sqlite://DRIVE:/dirA/dirB/dbfile jdbc:sqlite://COMPUTERNAME/shareA/dirB/dbfile 三、下面是使用SQLite的两段代码以供参考: 代码段1: 1 import java.sql.*; 2 import org.sqlite.JDBC; 3 4 public class SQLiteTest { 5 public static void main(String[] args) { 6 try { 7 // The SQLite (3.3.8) Database File 8 // This database has one table (pmp_countries) with 3 columns (country_id, country_code, country_name) 9 // It has like 237 records of all the countries I could think of. 10 String fileName = "c:/pmp.db"; 11 // Driver to Use 12 // http://www.zentus.com/sqlitejdbc/index.html 13 Class.forName("org.sqlite.JDBC"); 14 // Create Connection Object to SQLite Database 15 // If you want to only create a database in memory, exclude the +fileName 16 Connection conn = DriverManager.getConnection("jdbc:sqlite:"+fileName); 17 // Create a Statement object for the database connection, dunno what this stuff does though. 18 Statement stmt = conn.createStatement(); 19 // Create a result set object for the statement 20 ResultSet rs = stmt.executeQuery("SELECT * FROM pmp_countries ORDER BY country_name ASC"); 21 // Iterate the result set, printing each column 22 // if the column was an int, we could do rs.getInt(column name here) as well, etc. 23 while (rs.next()) { 24 String id = rs.getString("country_id"); // Column 1 25 String code = rs.getString("country_code"); //

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧