I am reading some data from a SQLite table by JDBC. Where the table has following columns:
[Id:Integer], [parentId:Integer], [Name:String], [Type:Integer], [Data:BLOB]
Now from the BLOB data I need to create some Unique identifier, thus the same BLOB will generate the same identifier every time. As of now I am creating a byte array from the blob and then making a toString
of it. Will it guarantees the uniqueness? And Is it CPU cycle efficient? As I have a lots of such records to process. Please suggest. Following is my code for the same.
public static void scanData(String dbName) {
String url = "jdbc:sqlite:C:/dbfolder/" + dbName;
try (Connection con = DriverManager.getConnection(url);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from someTable");) {
while (rs.next()) {
Integer type = rs.getInt("Type");
if (type != null && type.equals(3)) {
Integer rowId = rs.getInt("Id");
Integer parentId = rs.getInt("ParentID");
String name = rs.getString("Name");
System.out.println("rowId = " + rowId);
System.out.println("parentId = " + parentId);
System.out.println("name = " + name);
System.out.println("type = " + type);
InputStream is = rs.getBinaryStream("Data");
if (is != null) {
byte[] arr = IOUtils.toByteArray(is);
if (arr != null) {
System.out.println("Data = " + arr.toString());
}
}
System.out.println("---------------------------");
}
}
} catch (SQLException e) {
System.out.println(e.getMessage());
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
}
}
** IOUtils is used of : org.apache.commons.io.IOUtils