> Basically, the column with name "model" has data type BLOB, and null is > being written to that column.
I think your problem is with jdbc driver (I guess its setBytes implemented via the text data type, not blob) and with the fact that writeBuffer[0] is equal to 0. Changing writeBuffer[0] to something other than 0 could prove that. Pavel On Mon, Apr 4, 2011 at 1:58 PM, tiwaris <tiwa...@gmail.com> wrote: > > Hello, > > I created the following sample code to test the BLOB data type. > > I am using sqlite-jdbc driver provided at > (http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC). > > The following is the source code (SSCE). > > package org.sqlite; > > import java.sql.Connection; > import java.sql.DriverManager; > import java.sql.PreparedStatement; > import java.sql.ResultSet; > import java.sql.SQLException; > import java.sql.Statement; > > public class MainDriver { > > > public static void main(String[] args) { > new MainDriver(); > } > > > public MainDriver() { > > //Buffers to read and write > byte[] writeBuffer = new byte[10]; > byte[] readBuffer = null; > for (int i = 1; i < 10; i++) { > writeBuffer[i] = (byte)i; > } > > //Database objects > Connection conn = null; > Statement stat = null; > PreparedStatement prep = null; > > //Load the database driver > try { > System.loadLibrary("sqlite"); > Class.forName("org.sqlite.JDBC"); > } catch (Exception e) { > System.err.println("Could not load sqlite library or > instantiate the > database driver."); > System.err.println(e); > e.printStackTrace(); > return; > } > > //Open a connection to the database > try { > conn = DriverManager.getConnection("jdbc:sqlite:" + > "file.db"); > } catch (SQLException e) { > System.err.println("Could not open a connection to the > database with name > file.db"); > System.err.println(e); > e.printStackTrace(); > return; > } > > //Create a table > try { > stat = conn.createStatement(); > stat.execute("CREATE TABLE TEST (model BLOB NOT > NULL)"); > stat.close(); > } catch (SQLException e) { > System.err.println("The table could not be created."); > System.err.println(e); > e.printStackTrace(); > return; > } > > //Write buffer into the database > try { > conn.setAutoCommit(false); > prep = conn.prepareStatement("INSERT INTO TEST (model) > VALUES(?)"); > prep.setBytes(1, writeBuffer); > prep.addBatch(); > prep.executeBatch(); > conn.setAutoCommit(true); > prep.close(); > } catch (SQLException e) { > System.err.println("The buffer could not be written to > the database."); > System.err.println(e); > e.printStackTrace(); > return; > } > > //Read buffer from the database > try { > stat = conn.createStatement(); > ResultSet rs = stat.executeQuery("SELECT * FROM TEST"); > readBuffer = rs.getBytes(1); > rs.close(); > stat.close(); > } catch (SQLException e) { > System.err.println("The buffer could not be read"); > System.err.println(e); > e.printStackTrace(); > } > > //Close the database > try { > conn.close(); > } catch (SQLException e) { > System.err.println("Database could not be closed"); > System.err.println(e); > e.printStackTrace(); > } > > //Print the buffers > System.out.print("Write buffer = "); > for (int i = 0; i < writeBuffer.length; i++) { > System.out.print(writeBuffer[i]); > } > System.out.println(); > System.out.print("Read buffer = "); > for (int i = 0; i < readBuffer.length; i++) { > System.out.print(readBuffer[i]); > } > System.out.println(); > > //Check the md5sum > try { > java.security.MessageDigest digest = > java.security.MessageDigest.getInstance("MD5"); > byte[] md5sum = null; > java.math.BigInteger bigInt = null; > > //Write buffer > digest.reset(); > digest.update(writeBuffer); > md5sum = digest.digest(); > bigInt = new java.math.BigInteger(1, md5sum); > System.out.println("MD5 checksum of write buffer = " + > bigInt.toString(16)); > > //Read buffer > digest.reset(); > digest.update(readBuffer); > md5sum = digest.digest(); > bigInt = new java.math.BigInteger(1, md5sum); > System.out.println("MD5 checksum of read buffer = " + > bigInt.toString(16)); > } catch (Exception e) { > System.err.println("MD5 checksum not available"); > return; > } > } > > > } > > The exact error message is as follows. > > The buffer could not be written to the database. > java.sql.SQLException: TEST.model may not be NULL > java.sql.SQLException: TEST.model may not be NULL > at org.sqlite.DB.throwex(DB.java:427) > at org.sqlite.DB.executeBatch(DB.java:352) > at org.sqlite.PrepStmt.executeBatch(PrepStmt.java:104) > at org.sqlite.MainDriver.<init>(MainDriver.java:71) > at org.sqlite.MainDriver.main(MainDriver.java:14) > > > Basically, the column with name "model" has data type BLOB, and null is > being written to that column. When I build my application on linux, > everything works just fine. But, on windows, it works fine the downloaded > sqlite dll but not with my own dll. > > > > Pavel Ivanov-2 wrote: >> >>> I can create the dll, but it does not work with BLOB data type. It works >>> with other data types. The dll that I downloaded from the sqlite.org >>> website >>> works with BLOB data type. >>> >>> Any help would be appreciated. >> >> Any pointers on what doesn't work for you and how it works instead of >> intended behavior would be appreciated too. >> >> >> Pavel >> > -- > View this message in context: > http://old.nabble.com/Build-instructions-for-Winodws-with-unicode-support-tp31315626p31317012.html > Sent from the SQLite mailing list archive at Nabble.com. > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users