Paul Clapham wrote:My guess is that some of your column names are reserved words in Access's SQL dialect. In which case you should escape them, like this:
Martin Vajsar wrote:The ID column is of the Autonumber type. I believe you cannot redefine its value, therefore you must not include it in the INSERT statement (but I may be wrong). And you are not setting the first and fourth parameter anywhere, that could be a problem too.
Inserting a String (using PreparedStatement) is safe, assuming you don't exceed the target field size. MS Access has MEMO data type for long texts, however I'm not sure how that works with the JDBC/ODBC bridge.
Martin Vajsar wrote:Paul was right after all. "From" is a reserved word, you need to escape the column From as he has shown you (ie, [From]). The same might be true for To.
Much better would be to rename columns that match reserved words so that you wouldn't have to escape them.
Jacky Luk wrote:the timestamp is empty when it gets generated. I put =Now() and Now() at that field to no avail.
the newRec and oldRec contains an address of some sort. As you see, Object can be converted to string by toString(). But it is converted to an address?!
Martin Vajsar wrote:
Jacky Luk wrote:the timestamp is empty when it gets generated. I put =Now() and Now() at that field to no avail.
That is probably because you include the Timestamp column in the INSERT statement and set it to null (pst.setTimestamp(3, null)). Omit the Timestamp column altogether.
the newRec and oldRec contains an address of some sort. As you see, Object can be converted to string by toString(). But it is converted to an address?!
If I understand it correctly, you obtain a class name and some hex number by calling toString(). This is because you didn't override the default implementation of toString(). You need to override this method in all classes that will ever be passed into the LogDatabase method and put in the code that will create the string from their contents. This isn't actually a JDBC question, so if it is still not clear, please ask in the BJ forum.
By the way, method names should start with lowercase letters in Java.
Jacky Luk wrote:Like this? String str = "insert into Log (Type, Tbl, TS, oldRec, newRec) Values (?, ?, ,?, ?)";
I think I should override the class which is derived from Object. But I am passing the base class to LogDatabase. What should I override?
Martin Vajsar wrote:Why did you switch to setCharacterStream? If I understand it correctly, it has worked for you when you were passing in the strings using setString.
(I don't have any experience with LOB support in MS Access over JDBC/ODBC. I'm afraid it would be fraught with troubles.)
Consider Paul's rocket mass heater. |