While trying to run a transaction, I am always getting this error as a response while using the right TPK to encrypt my PINBLOCK which has been confirmed already.
Although, what i am not quite sure of is the algorithm that's been used for the encryption of this data which as a result is throwing this error because, the algorithm been expected is a DES algorithm (from the documentation given) which was giving the translatedPINBlock: 99-Wrong Format, but after updating my code to making use of
public String do3DESEncryption(String key, String text) {
String encryptedInfo = null;
try {
String key1 = key.substring(0, 16);
String key2 = key.substring(16);
encryptedInfo = doDESEncryption(key1, text);
encryptedInfo = doDESDecryption(key2, encryptedInfo);
encryptedInfo = doDESEncryption(key1, encryptedInfo);
} catch (Exception ex) {
System.out.println("do3DESEncryption error message"+ex.getMessage());
ex.printStackTrace();
}
return encryptedInfo;
}
The algorithm i was making use of before is stated below
public String doDESEncryption(String key, String text) {
String encryptedInfo = "";
try {
byte[] theCph = null;
byte[] theKey = null;
byte[] theMsg = null;
theKey = hexToBytes(key);
theMsg = hexToBytes(text);
DESKeySpec ks = new DESKeySpec(theKey);
SecretKeyFactory kf = SecretKeyFactory.getInstance("DES");
SecretKey ky = kf.generateSecret(ks);
Cipher cf = Cipher.getInstance("DES/ECB/NoPadding");
cf.init(Cipher.ENCRYPT_MODE, ky);
theCph = cf.doFinal(theMsg);
encryptedInfo = bytesToHex(theCph);
System.out.println("Just the ePINBLOCK"+encryptedInfo);
} catch (Exception e) {
e.printStackTrace();
}
return encryptedInfo;
}
I will like to know, if i am actually doing my encryption well cos, i have access to the client side only. I just want to be sure of the thing i am doing at my own end and to know, if there is any other correction i can make to avoid getting this error. translatedPINBlock: 99-Wrong Format
this is the error log from machine one
Postilion exception: [postilion.realtime.sdk.crypto.XPinLengthError]
Description: A cryptographic operation () involving key
'SBP_KVP' failed, because invalid data was supplied. The invalid data
was in field 'PIN'. The data was invalid because PIN length is
invalid. ID: [126] Data: [none]
at
postilion.realtime.sdk.crypto.impl.rg7000.ARG7000KeyImpl.processErrorCode(ARG7000KeyImpl.java:170)
at
postilion.realtime.sdk.crypto.impl.rg7000.RG7000DesKeyImpl.processErrorCode(RG7000DesKeyImpl.java:1320)
at
postilion.realtime.sdk.crypto.impl.rg7000.RG7000DesKeyImpl.processResponseAndErrorCode(RG7000DesKeyImpl.java:1378)
at
postilion.realtime.sdk.crypto.impl.rg7000.RG7000DesKvpIbmImpl.verifyPin(RG7000DesKvpIbmImpl.java:365)
at
postilion.realtime.sdk.crypto.DesKvpIbm.verifyPin(DesKvpIbm.java:613)
at
postilion.postcard.authorizers.IBMPinVerificationData.verify(IBMPinVerificationData.java:281)
at
postilion.postcard.authorizers.validators.ValidatorPinPostCard.validatePin(ValidatorPinPostCard.java:550)
at
postilion.postcard.authorizers.validators.ValidatorPinPostCard.validatePinAndPopulateMessageReasonCode(ValidatorPinPostCard.java:281)
at
postilion.postcard.authorizers.validators.ValidatorPinPostCard.validateOnline(ValidatorPinPostCard.java:78)
at
postilion.postcard.authorizers.pipeline.adapter.IssuerValidatorAdapter.process(IssuerValidatorAdapter.java:117)
at
postilion.postcard.authorizers.pipeline.Pipeline.process(Pipeline.java:315)
at
postilion.postcard.authorizers.AuthorizerPostCard.authorizeRequestOnline(AuthorizerPostCard.java:339)
at
postilion.realtime.apps.tranmgr.EventHandlerReqReqMessage.attemptLocalAuthorization(EventHandlerReqReqMessage.java:145)
at
postilion.realtime.apps.tranmgr.EventHandlerTranReq.processTran(EventHandlerTranReq.java:88)
at
postilion.realtime.apps.tranmgr.EventHandlerMessage.process(EventHandlerMessage.java:64)
at
postilion.realtime.apps.tranmgr.EventHandlerMessage.processMsg(EventHandlerMessage.java:40)
at
postilion.realtime.apps.tranmgr.TransactionManager.processNodeMessage(TransactionManager.java:1435)
at
postilion.realtime.apps.tranmgr.TransactionManager.processEvent(TransactionManager.java:1360)
at postilion.realtime.sdk.util.Processor.run(Processor.java:213) at
postilion.realtime.sdk.env.AppProcessor.run(AppProcessor.java:136)
[Error event 126]
Error log from machine 2
:: process0200
messageRetrievedFromStore[51]: 22314F270B978B54 INFO | jvm 1 |
2017/01/04 16:00:21 | Jan 04, 2017 4:00:21 PM
hsmm.ncs.core.MessageProcessor processPINBlock INFO | jvm 1 |
2017/01/04 16:00:21 | INFO: MessageProcessor :: process0200 ::
translatedPINBlock: 99-Wrong Format INFO | jvm 1 | 2017/01/04 16:00:21 | Jan 04, 2017 4:00:21 PM
hsmm.ncs.core.MessageProcessor process0200
Current practice requires the encryption to be 3DES, possibly with a double length key.
Related
Quick summary of issue - when I set the RawString to text, the email with attachment is sent and properly named. When I set the attachment to a RawString message, I get the error "The part 'PartAttachment' of message 'msg_Email' contained a null value at the end of the construct block."
I have created my own RawString class which I have used before. The orchestration receives a CSV file via a pass-thru pipline. Following some documentation I found, I receive a XmlDocument, and in the next shape, I construct the RawString as follows:
msg_Raw_String.MessagePart_1 = msg_Ledger6002_File_XmlDoc;
However if I set the to dummy text in RawString, the email with attachment is sent (the attachment is just a text file with the value below:
msg_Email.PartAttachment = new XXXLedger6002.Component.RawString("Test Text");
Full code in message assignment:
msg_Email.BodyPart = new XXXLedger6002.Component.RawString("See attached email. Method 2 Dynamic");
// Force some value to make sure it is not null
//msg_Email.PartAttachment = new Ledger6002.Component.RawString("Test Text");
// Tried both of these, same error:
//msg_Email.PartAttachment = msg_Ledger6002_File_XmlDoc;
msg_Email.PartAttachment = msg_Raw_String.MessagePart_1;
// syntax doesn't allow this:
// msg_Email.PartAttachment = msg_Raw_String;
// Set the filename as it should display on the attachment in the email
// (drop the path, just the filename/extension)
attachmentName = System.IO.Path.GetFileName(
msg_Ledger6002_File_XmlDoc(FILE.ReceivedFileName));
msg_Email.PartAttachment(MIME.FileName) = attachmentName;
//msg_Email.BodyPart(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";//
//msg_Email.AttachmentPart(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
msg_Email(SMTP.Subject) = "Ledger6002 File";
msg_Email(SMTP.SMTPTo) = msg_Config_Email.smtpToEmail;
msg_Email(SMTP.From) = msg_Config_Email.smtpFromEmail;
msg_Email(SMTP.SMTPAuthenticate) = 0; // do not authenticate to SMTP server
msg_Email(SMTP.SMTPHost) = msg_Config_Email.smptHostName;
// msg_Email(SMTP.EmailBodyText) = "UTF-8";
msg_Email(SMTP.EmailBodyTextCharset) = "UTF-8";
msg_Email(SMTP.MessagePartsAttachments) = 2;
// No email generated with comment out line, trying same without mailto:
SMTP_Dyn_Email(Microsoft.XLANGs.BaseTypes.Address) = "mailto:" + msg_Config_Email.smtpToEmail;
SMTP_Dyn_Email(Microsoft.XLANGs.BaseTypes.TransportType) = "SMTP";
Error:
xlang/s engine event log entry: Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'Ledger6002.Logic.Ledger6002_Process_File(9eb6993c-87d0-7bf0-b0bf-e1f684000af2)'.
The service instance will remain suspended until administratively resumed or terminated.
If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
InstanceId: ecaa7ed2-04c1-46b9-b845-cf3211b83387
Shape name: Send_Dyn_Email
ShapeId: 4ada59c3-367e-40b4-babc-d0d9999feb77
Exception thrown from: segment 1, progress 60
Inner exception: The part 'PartAttachment' of message 'msg_Email' contained a null value at the end of the construct block.
Exception type: NullPartException
Source: Microsoft.XLANGs.Engine
Target Site: System.IO.Stream Persist(System.String ByRef, Boolean)
The following is a stack trace that identifies the location where the exception occured
at Microsoft.XLANGs.Core.CustomFormattedPart.Persist(String& encoding, Boolean wantEncoding)
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXXlangStore.StagePartData(Part part)
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXXlangStore.PrepareMessage(XLANGMessage msg, IList promoteProps, IList toPromote)
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXXlangStore.WriteMessageState(IBTPEPInfoLookup pepLookup, Guid portId, XLANGMessage msg, Segment seg, String opname, String url, IList promoteProps, Boolean track, IList toPromote)
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXLogicalPortBinding.SendMessage(XLANGMessage msg, XlangStore store, Segment seg, OperationInfo op, IList additionalProps, IList toPromote, Boolean ignoreRoutingFailure)
at Microsoft.BizTalk.XLANGs.BTXEngine.BTXPortBase.SendMessage(Int32 iOperation, XLANGMessage msg, Correlation[] initCorrelations, Correlation[] followCorrelations, Context cxt, Segment seg, ActivityFlags flags)
at Ledger6002.Logic.Ledger6002_Process_File.segment1(StopConditions stopOn)
at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)
The following is a get-around that seems to work.
msg_Email.PartAttachment = new SBA.Ledger6002.Component.RawString(
msg_Raw_String.MessagePart_1.ToString());
If anybody can explain why I just can't set it to msg_Raw_String.MessagePart_1, I would love to know.
I'm working in report module, in order to do that I'm creating different stored procedures. I create the procedure with in parameters and then create a class to map the row (resultSet)
I think that's the best way to work arround performance and clarity.(what do you think about that?)
I'm using play framework and ebean orm (2.7.7)
I'm calling the store procedure and getting the resultSet, but I would like to use ebean in order to cast automaticly the row to model... other option is take the row-cell and cast it in a property but I'm trying to avoid it.
This is the current approach
Is this the best way to call an stored procedure?
Transaction tx = Ebean.beginTransaction();
String sql = "{CALL report(?, ?, ?, ?, ?, ?)}";
CallableStatement callableStatement = null;
try {
Connection dbConnection = tx.getConnection();
callableStatement = dbConnection.prepareCall(sql);
callableStatement.setInt(1, 3);
callableStatement.setInt(2, 5);
callableStatement.setInt(3, 2013);
callableStatement.setInt(4, 1);
callableStatement.setInt(5, 2014);
callableStatement.setInt(6, 5);
ResultSet rs = callableStatement.executeQuery(sql);
while (rs.next()) {
//HOW TO CONVER row -> model ?
}
Ebean.commitTransaction();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I've discarded RawSQL and Query because received an error
RuntimeException: Error parsing sql, can not find SELECT keyword in: xxxxx
Also I found other option... using CallableSql
String sql = "{call sp_order_mod(?,?)}";
CallableSql cs = Ebean.createCallableSql(sql);
cs.setParameter(1, "turbo");
cs.registerOut(2, Types.INTEGER);
Ebean.execute(cs);
// read the out parameter
Integer returnValue = (Integer) cs.getObject(2);
but in this case I need to return a ResultSet not simply parameter.
I'm going to share my own solution.
I get a class called ResultSetUtils.(you can google it some implementation)
I added a generic method in order to return a typed list from resultset
public static <T> List<T> populateInList(Class<T> c, final ResultSet rs) {
List<T> listTyped = new ArrayList<T>();
try {
if (rs != null) {
while (rs.next()) {
T o = c.newInstance();
// MAGIC LINE
populate(o, rs);
listTyped.add(o);
}
rs.close();
}
} catch (final Exception e) {
// TODO Auto-generated catch block
System.err.println(e.getMessage());
}
return listTyped;
}
This class to do the population use org.apache.commons.beanutils package
BeanUtils.populate(bean, propertiesRealName);
Using
private static void callingProcedureTest() {
Logger.debug("Init callingProcedureTest");
Transaction tx = Ebean.beginTransaction();
// String sql = "{CALL sp_report_test(3, 5, 2013, 1, 2014, 5)}";
String sql = "CALL sp_report_test(?, ?, ?, ?, ?, ?);";
try {
Connection dbConnection = tx.getConnection();
CallableStatement callableStatement = dbConnection.prepareCall(sql);
callableStatement.setInt(1, 3);
callableStatement.setInt(2, 5);
callableStatement.setInt(3, 2013);
callableStatement.setInt(4, 1);
callableStatement.setInt(5, 2014);
callableStatement.setInt(6, 5);
Logger.debug("SQL > " + sql);
ResultSet rs = callableStatement.executeQuery();
Class<ReportTestResult> c = ReportTestResult.class;
//************** MAGIC LINE, converting ResultSet to Model
List<ReportTestResult> listResult = ResultSetUtils.populateInList(c, rs);
for (ReportTestResult item : listResult) {
Logger.debug("item.firstName> " + item.firstName);
Logger.debug("item.lastName > " + item.lastName);
Logger.debug("item.year > " + item.year);
}
Ebean.commitTransaction();
} catch (Exception e) {
Ebean.rollbackTransaction();
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
Ebean.endTransaction();
}
}
Plus about architecture and implementation
For each report I'm going to create:
a Result class (eg ReportTestResult)
intention: represent a row of report | simple DTO
a Param class (eg ReportTestParam),
intention: represent the parameters (inputs / ouputs), filters of the report
This class should implements
public interface ReportParam {
public int countParameteres();
public void setParametersInCallableStatement(CallableStatement callableStatement) throws SQLException;
}
a Report class (eg ReportTestReport) this class should extends ReportBase
intention: Knows the stored procedure's name, parameters and dto result
public class ReportTestReport extends ReportBase<ReportTestResult, ReportTestParam> {
#Override
protected String getProcedureName() {
return STORED_NAME;
}
}
many Adapters...
Each report could displayed in different charts, In this case I'm using HighCharts. Order to arrange it, I'm creating different adapters to do that.
EG:
class ReportTestHighChartsAdapter
intention: convert a list of ReportTestResult to series and configure different options of report (eg, title, xAxis etc)
public OptionsHC buildColumnReportV1(){
OptionsHC optionChart = new OptionsHC();
optionChart.chart = new ChartHC("column");
this.setTitle(optionChart);
optionChart.yAxis = new AxisHC(new TitleHC("Fruit eaten"));
.....
return optionChart;
}
OptionsHC is a class that represent option obj in the HighCharts framework.
The final step is converting OptionHC to Json and use it in JavaScript (common use of highCharts)
What's ReportBase?
ReportBase class has the strategy to implements the final called to DB, also manage the transaction
public class ReportTestReport extends ReportBase<ReportTestResult, ReportTestParam> {
...
protected List<TResult> execute(Class<TResult> classT) {
List<TResult> resultDTO = null;
CallableStatement callableStatement = null;
Logger.debug("Running procedure> " + this.getProcedureName());
Transaction tx = Ebean.beginTransaction();
String sql = ProcedureBuilder.build(this.getProcedureName(), this.countParameters());
Logger.debug("SQL > " + sql);
try {
Connection dbConnection = tx.getConnection();
callableStatement = dbConnection.prepareCall(sql);
this.getFilter().setParametersInCallableStatement(callableStatement);
ResultSet rs = callableStatement.executeQuery();
resultDTO = ResultSetUtils.populateInList(classT, rs);
Ebean.commitTransaction();
Logger.debug("commitTransaction > " + sql);
} catch (Exception e) {
Ebean.rollbackTransaction();
Logger.debug("rollbackTransaction > " + sql);
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
Ebean.endTransaction();
}
return resultDTO;
}
...
}
Currently the support for stored procedures in Ebean is not orientated to what you are trying to do. Hence you are not going to get much joy from using CallableSql or RawSql.
>> a class to map the row (resultSet) I think that's the best way to work around performance and clarity
Yes, I can understand your motivation.
>> How to convert ResultSet into model
Currently there is no good solution. The best solution would be to enhance RawSql so that you can set a ResultSet onto it. One of the things RawSql does is provide the mapping of resultSet columns to model properties and that is what Ebean needs internally. The enhancement/code change would be to be able to set a resultSet onto the RawSql object ... and get Ebean internally to skip the creation of the resultSet ( preparedStatement, binding parameters and executeQuery()). In terms of Ebean internals this is all done in the CQuery.prepareBindExecuteQueryWithOption() method. That is, if the RawSql has already provided a resultSet skip those things.
The big benefit of doing this rather than just rolling your own row -> model mapping code is that the resulting beans would all still have lazy loading / partial object knowledge etc. They would behave exactly like any other beans that Ebean builds as part of it query mechanism.
So that said, I'm personally away for a week ... so you aren't going to hear back from me until after that. If you want to get into it yourself then internally CQuery.prepareBindExecuteQueryWithOption() is the code you will need to modify.
If you have been following the ebean google group you'll know that but just in case you have not been note that the Model and Finder objects from Play have been incorporated into Ebean just in the last week. This helps both projects ... reduces confusion etc. The Ebean source in github master is at 4.0.4 and the bytecode enhancement in 4.x is different and I don't believe supported in Play.
I'm basically going offline for a week now so I'll look back into this after that.
Cheers, Rob.
Below is simple Login system. At the moment it will allow me to enter a blank username and password, into the table even though each index is specified as being NOT NULL? It wont allow me to enter duplicates which is what I wanted but how do I catch blank parameters from being entered? What am I missing?
Registration Servlet
....
LoginService loginService = new LoginService();
connection = loginService.getConnection(connection);
loginService.addNewUser(preparedStatement, connection, newUserId, newUserPassword, newUserFirstName, newUserLastName);
...
LoginService method addNewUser
public void addNewUser(PreparedStatement ps, Connection connection, String newUserId, String newUserPassword,String newUserFirstName,String newUserLastname) throws SQLException
{
ps = connection.prepareStatement("INSERT INTO users (userId ,password , userFirstName, userLastName)VALUES(?,?,?,?)");
ps.setString(1, newUserId);
ps.setString(2, newUserPassword);
ps.setString(3, newUserFirstName);
ps.setString(4, newUserLastname);
ps.executeUpdate();
}
To get around of your current issue, you can add this to the beginning of addNewUser method (before the line: ps = connection.prepareStatement("...");)
if (newUserId != null && "".equals(newUserId.trim()))
newUserId = null;
if (newUserPassword != null && "".equals(newUserPassword.trim()))
newUserPassword = null;
You should pass real NULL value in the JDBC parameters (empty strings are not good enough)
What the hey does this MySql error message mean?
java.sql.SQLException: boo!
springframework.dao.TransientDataAccessResourceException: CallableStatementCallback; SQL [{call sp_MyStoredProc(?, ?, ?)}]; boo!
It's not particularly meaningful that's for sure. Has anybody come across this and is able to translate to less lazy~developer~ish...?
I am accessing via org.springframework.jdbc.object.StoredProcedure
I am using org.springframework.jdbc-3.1.3
#Update
The offending lines are in CallableStatetement.java (2269-2271)
if (!found) {
throw SQLError.createSQLException("boo!", "S1000", this.connection.getExceptionInterceptor());`
}
Attching the sources for mysql-connector-java-5.1.18.jar and tracing though the code reveal that the correct message should be along the lines of 'mismatch between declared and actual parameters' or similar.
Indeed correctly declaring my output parameter
declareParameter(new SqlOutParameter("output", Types.INTEGER));
rather than
declareParameter(new SqlParameter("output", Types.INTEGER));
fixed my problem. But a more meaningful error message would have saved precious time. I shall make this suggestion to the MySql Connector/J Development team.
As stated in the update to the question this is commonly caused by incorrectly using a CallableStatement. For example:
Stored Procedure uses 2 parameters, one in and one out:
CREATE DEFINER=`example`#`localhost` PROCEDURE `sp_getSensorLocation`(IN in_id VARCHAR(128), OUT loc VARCHAR(128))
BEGIN
SELECT LOCATION INTO loc FROM table.SENSORS
WHERE ID = in_id;
END
but the call to it only uses 1:
private String getSensorLocation(String sensorID) {
String location = "";
Connection c = dbr.getConnection();
String prepStatement = "{ call sp_getSensorLocation(?) } ";
try {
callableStatement cs = c.prepareCall(prepStatement);
cs.setString(1, sensorID);
ResultSet rs = cs.executeQuery();
if (rs.next()) {
location = rs.getString(1);
}
} catch (SQLException ex) {
LOG.error("Error:", ex);
}
dbr.closeConnection(c, rs, cs);
return location;
}
When the correct code is really:
private String getSensorLocation(String sensorID) {
String location = "";
Connection c = dbr.getConnection();
String prepStatement = "{ call sp_getSensorLocation(?, ?) } ";
try {
CallableStatement cs = c.prepareCall(prepStatement);
cs.setString(1, sensorID);
cs.execute();
location = cs.getString(2);
} catch (SQLException ex) {
LOG.error("Error:", ex);
}
dbr.closeConnection(c, rs, cs);
return location;
}
Notice I also changed to cs.execute as I don't expect a result set and would have issues with this as well (the example is taken from someone else's code I'm fixing, the joys -_-)
The weird behavior is that a java.sql.Timestamp that I create using the System.currentTimeMillis() method, is stored in my MySQL database as 1970-01-01 01:00:00.
The two timestamps I am creating are to mark the beginning and end of a monitoring task I am trying to perform, what follows are excepts from the code where the behavior occurs
final long startTime = System.currentTimeMillis();
while(numberOfTimeStepsPassed < numTimeStep) {
/*
* Code in here
*/
}
final long endTime = System.currentTimeMillis();
return mysqlConnection.insertDataInformation(matrixOfRawData, name,Long.toString(startTime),
Long.toString(endTime), Integer.toString(numTimeStep),
Integer.toString(matrixOfRawData[0].length), owner,
type);
And here is the code used for inserting the time stamps and other data into the MySQL database
public String insertDataInformation(final double [][] matrix,
final String ... params) {
getConnection(lookUpName);
String id = "";
PreparedStatement dataInformationInsert = null;
try {
dataInformationInsert =
databaseConnection.prepareStatement(DATA_INFORMATION_PREPARED_STATEMENT);
id = DatabaseUtils.createUniqueId();
int stepsMonitored = Integer.parseInt(params[STEPS_MONITORED]);
int numberOfMarkets = Integer.parseInt(params[NUMBER_OF_MARKETS]);
dataInformationInsert.setNString(ID_INDEX, id);
dataInformationInsert.setNString(NAME_INDEX, params[0]);
dataInformationInsert.setTimestamp(START_INDEX, new Timestamp(Long.parseLong(params[START_INDEX])));
dataInformationInsert.setTimestamp(END_INDEX, new Timestamp(Long.parseLong(params[END_INDEX])));
dataInformationInsert.setInt(STEPS_INDEX, stepsMonitored);
dataInformationInsert.setInt(MARKETS_INDEX, numberOfMarkets);
dataInformationInsert.setNString(OWNER_INDEX, params[OWNER]);
dataInformationInsert.setNString(TYPE_INDEX, params[TYPE]);
dataInformationInsert.executeUpdate();
insertRawMatrix(matrix, id, Integer.toString(stepsMonitored), Integer.toString(numberOfMarkets));
} catch (SQLException sqple) {
// TODO Auto-generated catch block
sqple.printStackTrace();
System.out.println(sqple.getSQLState());
} finally {
close(dataInformationInsert);
dataInformationInsert = null;
close(databaseConnection);
}
return id;
}
The important lines of code are :
dataInformationInsert.setTimestamp(START_INDEX, new Timestamp(Long.parseLong(params[START_INDEX])));
dataInformationInsert.setTimestamp(END_INDEX, new Timestamp(Long.parseLong(params[END_INDEX])));
The JavaDocs on the TimeStamp ( http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/Timestamp.html ) says that it takes in time in milliseconds since 1st January 1970 and a simple print test confirms this.
What I am looking for is:
A reason for this behavior when trying to store timestamps in a MySQL database through java.sql.Timestamp?
Any solutions to this behavior?
Any possible alternatives?
Any possible improvements?
EDIT:
Been asked to include what START_INDEX and END_INDEX are:
private static final int END_INDEX = 4;
private static final int START_INDEX = 3;
Apologises for not putting them in the original post.
Okay, look at your call:
insertDataInformation(matrixOfRawData, name, Long.toString(startTime),
Long.toString(endTime), Integer.toString(numTimeStep),
Integer.toString(matrixOfRawData[0].length), owner,
type);
So params will have values:
0: name
1: start time
2: end time
3: numTimeStep
4: matrixOfRowData[0].length
5: owner
6: type
Then you're doing:
dataInformationInsert.setTimestamp(START_INDEX,
new Timestamp(Long.parseLong(params[START_INDEX])));
... where START_INDEX is 3.
So you're using the value corresponding to numTimeStep as the value for the timestamp... I suspect you don't want to do that.
I would strongly advise you to create a simple object type (possibly a nested type in the same class) to let you pass these parameters in a strongly typed, simple to get right fashion. The string conversion and the access by index are both unwarranted, and can easily give rise to errors.