/// /// 创建一个连接到指定数据文件的SQLiteConnection,并Open /// 如果文件不存在,创建之 /// /// /// public static SQLiteConnection OpenConnection(string dataFile) { if (dataFile == null) throw new ArgumentNullException("dataFile=null");
if (!File.Exists(dataFile)) { SQLiteConnection.CreateFile(dataFile); }
SQLiteConnection conn = new SQLiteConnection(); SQLiteConnectionStringBuilder conStr = new SQLiteConnectionStringBuilder(); conStr.DataSource = dataFile; conn.ConnectionString = conStr.ToString(); conn.Open(); return conn; }
/// /// 读取或设置SQLiteManager使用的数据库连接 /// public SQLiteConnection Connection { get { return this._conn; } set { if (value == null) { throw new ArgumentNullException(); } this._conn = value; } }
protected void EnsureConnection() { if (this._conn == null) { throw new Exception("SQLiteManager.Connection=null"); } }
public string GetDataFile() { return this._dataFile; }
/// /// 判断表table是否存在 /// /// /// public bool TableExists(string table) { if (table == null) throw new ArgumentNullException("table=null"); this.EnsureConnection(); // SELECT count(*) FROM sqlite_master WHERE type='table' AND name='test'; SQLiteCommand cmd = new SQLiteCommand("SELECT count(*) as c FROM sqlite_master WHERE type='table' AND name=@tableName "); cmd.Connection = this.Connection; cmd.Parameters.Add(new SQLiteParameter("tableName", table)); SQLiteDataReader reader = cmd.ExecuteReader(); reader.Read(); int c = reader.GetInt32(0); reader.Close(); reader.Dispose(); cmd.Dispose(); //return false; return c == 1; }
/// /// 执行SQL,返回受影响的行数 /// 可用于执行表创建语句 /// paramArr == null 表示无参数 /// /// /// public int ExecuteNonQuery(string sql,SQLiteParameter[] paramArr) { if (sql == null) { throw new ArgumentNullException("sql=null"); } this.EnsureConnection();
if (this.ShowSql) { Console.WriteLine("SQL: " + sql); }
SQLiteCommand cmd = new SQLiteCommand(); cmd.CommandText = sql; if (paramArr != null) { foreach (SQLiteParameter p in paramArr) { cmd.Parameters.Add(p); } } cmd.Connection = this.Connection; int c = cmd.ExecuteNonQuery(); cmd.Dispose(); return c; }
SQLiteCommand cmd = new SQLiteCommand(sql, this.Connection); if (paramArr != null) { foreach (SQLiteParameter p in paramArr) { cmd.Parameters.Add(p); } } SQLiteDataReader reader = cmd.ExecuteReader(); object result = null; if (readerWrapper != null) { result = readerWrapper(reader); } else { result = reader; } reader.Close(); reader.Dispose(); cmd.Dispose(); return result; }
/// /// 执行SQL,返回结果集,使用RowWrapper对每一行进行包装 /// 如果结果集为空,那么返回空List (List.Count=0) /// rowWrapper = null时,使用WrapRowToDictionary /// /// /// /// /// public List
测试类:
使用TestDrivern.NET
using System; using System.Collections.Generic; using System.Linq; using System.Text;
using System.Data.SQLite;
namespace SQLite {
class Test {
private SQLiteHelper _mgr;
public Test() { this._mgr = new SQLiteHelper("sqlite.db"); this._mgr.Open(); }
public void TestTableExists() { Console.WriteLine("表test是否存在: " + this._mgr.TableExists("test")); }
public void TestExecuteRow() { List list = this._mgr.ExecuteRow("select * from test", null, null); foreach (object o in list) { Dictionary d = (Dictionary) o; foreach (string k in d.Keys) { Console.Write(k + "=" + d[k] + ","); } Console.WriteLine(); } }
public void TestSave() { Dictionary entity = new Dictionary(); entity.Add("username", "u1"); entity.Add("password", "p1"); this._mgr.Save("test", entity); }
public void TestUpdate() { Dictionary entity = new Dictionary(); entity.Add("username", "u1"); entity.Add("password", "123456");
int c = this._mgr.Update("test", entity, "username=@username", new System.Data.SQLite.SQLiteParameter[] { new SQLiteParameter("username","u1") }); Console.WriteLine(c); }
public void TestQueryOne() { Dictionary entity = this._mgr.QueryOne("test", "username", "a"); foreach (string k in entity.Keys) { Console.Write(k + "=" + entity[k] + ","); } }
public void TestDelete() { int c = this._mgr.Delete("test", "username=@username", new SQLiteParameter[] { new SQLiteParameter("username","a") }); Console.WriteLine("c=" + c); }
public static void Test0() { Test t = new Test(); t.TestTableExists(); t.TestExecuteRow();
最近mysql数据库经常死掉,用命令net stop mysql命令也无法停掉,关闭Tomcat的时候,出现Waiting for N instance(s) to be deallocated 信息。查了下,大概就是程序没有对数据库连接释放,导致Connection泄露了。因为用的是开元集成的平台,内部程序也不可能一下子给改掉的,就验证一下咯。启动Tomcat,用户登录系统,用netstat -
var a=document.getElementsByClassName('textinput');
var b=[];
for(var m=0;m<a.length;m++){
if(a[m].getAttribute('placeholder')!=null)
b.push(a[m])
}
var l
错误信息:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cartService': Scope 'session' is not active for the current thread; consider defining a scoped
这个开源软件包是国内的一位高手自行研制开发的,正如他所说的一样,我觉得它可以使一个工作流引擎上一个台阶。。。。。。欢迎大家使用,并提出意见和建议。。。
----------转帖---------------------------------------------------
IK Expression是一个开源的(OpenSource),可扩展的(Extensible),基于java语言
1.在thingking in java 的第四版第六章中明确的说了,子类对象中封装了父类对象,
2."When you create an object of the derived class, it contains within it a subobject of the base class. This subobject is the sam
http://www.sap.com/corporate-en/press.epx?PressID=14787
有机会研究下EIM家族的两个新产品~~~~
New features of the 4.0 releases of BI and EIM solutions include:
Real-time in-memory computing –
结构
继承关系
public final class Manifest extends Objectjava.lang.Objectandroid.Manifest
内部类
class Manifest.permission权限
class Manifest.permission_group权限组
构造函数
public Manifest () 详细 androi
关键字:Oracle实现类split函数的方
项目里需要保存结构数据,批量传到后他进行保存,为了减小数据量,子集拼装的格式,使用存储过程进行保存。保存的过程中需要对数据解析。但是oracle没有Java中split类似的函数。从网上找了一个,也补全了一下。
CREATE OR REPLACE TYPE t_split_100 IS TABLE OF VARCHAR2(100);
cr