[code="java"]
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite://e:/hello.db");
Statement stmt = conn.createStatement();
[/code]
使用jdbc连接sqlite3时,blob数据该怎么存入取出?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- jiangguangxian 2011-11-30 08:27关注
我只能给你两个c#的代码,给你一点参考:
[code="java"]
public static Dictionary GetBlob(string dirPath)
{
Dictionary dic = new Dictionary();List<string> lst = new List<string>(); string strSQL = "select * from Resource"; SQLiteCommand cmd = Connection.CreateCommand(); cmd.CommandText = strSQL; try { if (Connection.State != ConnectionState.Open) Connection.Open(); SQLiteDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { string itemId = dataReader["ID"].ToString(); int nDataLen = (int)dataReader.GetBytes(1, 0, null, 0, 0); byte[] pbyData = new byte[nDataLen]; dataReader.GetBytes(1, 0, pbyData, 0, nDataLen); string fileName = string.Format(Path.Combine(dirPath, itemId + ".zip")); dic[itemId] = fileName; FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); fs.Write(pbyData, 0, nDataLen); fs.Close(); } dataReader.Close(); } catch (Exception ex) { throw ex; } finally { cmd.Dispose(); Connection.Close(); } return dic; } public static int InsertBlob(string cmdText, byte[] data) { SQLiteCommand command = new SQLiteCommand(); int nRowCount = 0; try { if (Connection.State != ConnectionState.Open) Connection.Open(); SQLiteParameter para = new SQLiteParameter("data", DbType.Binary); para.Value = data; command.Parameters.Add(para); command.Connection = Connection; command.CommandText = cmdText; command.CommandType = CommandType.Text; command.CommandTimeout = 30; nRowCount = command.ExecuteNonQuery(); } catch (Exception ex) { } finally { command.Dispose(); Connection.Close(); } return nRowCount; }
[/code]
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 delta降尺度计算的一些细节,有偿
- ¥15 Arduino红外遥控代码有问题
- ¥15 数值计算离散正交多项式
- ¥30 数值计算均差系数编程
- ¥15 redis-full-check比较 两个集群的数据出错
- ¥15 Matlab编程问题
- ¥15 训练的多模态特征融合模型准确度很低怎么办
- ¥15 kylin启动报错log4j类冲突
- ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
- ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序