![]() ![]() ("Product version: " + dm.getDatabaseProductVersion()) ("Product name: " + dm.getDatabaseProductName()) ("Driver version: " + dm.getDriverVersion()) ("Connected to the database") ĭatabaseMetaData dm = (DatabaseMetaData) conn.getMetaData() * This program demonstrates making JDBC connection to a SQLite database.Ĭonnection conn = DriverManager.getConnection(dbURL) Making SQLite JDBC connectionThe following example program creates a connection to a SQLite database file product.db which is in the same directory as the program, prints some database metadata information, and closes the connection: package With this SQLite JDBC library, you have to load the driver as follows: Class.forName("") Or: DriverManager.registerDriver(new ()) 4. Jdbc:sqlite:C:/work/product.dbAnd here is the syntax of database connection URL for memory database: Jdbc:sqlite:database_file_pathWhere database_file_path can be either relative or absolute path. SQLite JDBC database connection URLThe SQLite JDBC driver can load a SQLite database from file system or creates one in memory.Here is the syntax of database connection URL for file system database: As of this writing, the latest version is 3.7.2 which corresponds to the jar file sqlite-jdbc-3.7.2.jar.Beside Java class files, the jar file includes SQLite binaries for Windows, Linux and Mac (for both 32-bit and 64-bit).Place the sqlite-jdbc-VERSION.jar into your classpath.Ģ. The download is categorized by versions, so browse a directory for a specific version you want: 3.5.9, 3.6.16, 3.7.2, etc. ![]() Download SQLite JDBC driverYou can download the latest version of JDBC driver for SQLite here. Although there is no official JDBC driver library from there is one provided by – an XML Database Management System project. The following readFile method reads a file and returns an array of bytes that we can pass to the setBytes method.SQLite is a simple, small, fast, reliable, server-less, zero-configuration and no-installation SQL database library which is running in-process with the client application. ![]() Notice that the SQLiteJDBC driver does not implement the setBinaryStream() method, therefore, you must use the setBytes method instead. Finally, execute the UPDATE statement by calling the executeUpdate() method of the PreparedStatement object.After that, supply the values to the corresponding parameters using the set* methods of the PreparedStatement object.Then, create a PreparedStatement object from the Connection object.Next, connect to the SQLite database to get the Connection object.To update the picture column with the data from the picture file: ![]() Second, prepare a picture file and place it in a folder e.g., C:\temp as follows: Materials Code language: SQL (Structured Query Language) ( sql ) ALTER TABLE materials ADD COLUMN picture blob Code language: SQL (Structured Query Language) ( sql ) Insert BLOB data into SQLite databaseįirst, query data from the materials table to view its content: SELECT id, The following ALTER TABLE statement adds the picture column to the materials table. To do this, we add a column whose data type is BLOB to the materials table. Suppose we have to store a picture for each material in the materials table. Summary: this tutorial shows you step by step how to update and select the BLOB from an SQLite database.įor the demonstration, we will use the materials table that we created in the creating table tutorial. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |