SQLite implementations in Java and C#
I've been using SQLite in my Java and C# applications, making use of the System.Data.SQLite library for C# and the Zentus SQLiteJDBC Driver for Java.
I've noticed that the Java implementation allows the use of the readily available SQL libraries that are included with the default Java installation whereas the C# implementation has to use specific SQLite versions of the C# equivalent.
Example:
C#
SQLiteConnection connection = null;
SQLiteCommand command = null;
SQLiteDataReader dReader开发者_如何学编程 = null;
float[] _data;
try
{
connection = new SQLiteConnection(_connectionString);
connection.Open();
Java
Connection connection = null;
PreparedStatement ps = null;
ResultSet rs = null;
float _data[];
try
{
connection = DriverManager.getConnection(_connectionString);
Statement st = connection.createStatement();
Is this down to how SQL databases are utilised in the languages or is it due to the implementations of the libraries, I'm interested to know more about the details leading to their usage.
I believe that Connection
, PreparedStatement
, and ResultSet
are all interfaces, I believe. You could do the same thing in C# with IDbConnection
, IDbCommand
and IDataReader
instead of the concrete SQLite implementations.
Java implementation allows the use of the readily available SQL libraries that are included with the default Java installation, but the connection string does differ , and you do need to import different driver(jar) for different types of databases.
So if I may say , Java as provided a wrapper as long as JDBC drivers are written for a database you want to use with java.
You can write the following in C#:
IDbConnection connection = null;
IDbCommand command = null;
IDataReader dReader = null;
float[] _data;
try
{
connection = new SQLiteConnection(_connectionString);
connection.Open();
The only thing that differs is that in Java there is a helper class DriverManager
.
NOTE: The DataSource interface, new in the JDBC 2.0 API, provides another way to connect to a data source. The use of a DataSource object is the preferred means of connecting to a data source.
If you use DataSource
, which is the preferred way of obtaining a connection, according to the DriverManager
documentation, you'll also need to call the specific constructor of the SQLite implementation.
精彩评论