私は弊社の出席管理システムを作成しており、すべての従業員の出席は指紋バイオメトリックマシンによって生成されたテキストファイル上にあります。問題は、文字列の日付の配列をテキストファイルから変換してデータベースに保存しようとしていますが、それは "unparseable date error"を出してしまうことです。参照用のコードを参照してください。文字列をutilに変換する日付変換
public void getReadTextFile(String path) throws ParseException{
sql = new String("INSERT INTO logs(EmpID, ValidDate, ValidTime,Processed, PRDate) VALUES(?,?,?,?,?)");
BufferedReader br = null;
String[] ID = new String[3000];
java.sql.Date[] vDate = new java.sql.Date[3000];
Time[] vTime = new Time[3000];
Date date = new Date();
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try{
FileInputStream fsStream = new FileInputStream(path);
br = new BufferedReader(new InputStreamReader(fsStream));
String strLine;
br.readLine();
int i = 0;
while((strLine = br.readLine()) != null){
String[] arr = strLine.split("\\s+");
java.util.Date qDate = format.parse(arr[5]);
ID[i] = arr[2];
vDate[i] = new java.sql.Date(qDate.getTime());
vTime[i] = java.sql.Time.valueOf(arr[6]);
java.sql.Date sqldate = new java.sql.Date(date.getTime());
pstmt = data.prepareStatement(sql);
pstmt.setString(1, arr[2]);
pstmt.setDate(2, vDate[i]);
pstmt.setTime(3, vTime[i]);
pstmt.setInt(4, 1);
pstmt.setDate(5, sqldate);
}
i++;
}catch(IOException ex){
System.out.println(ex.getMessage());
}catch(SQLException ev){
//System.out.println(ev.getMessage());
ev.printStackTrace();
}catch(ParseException pe){
pe.printStackTrace();
}
finally{
try{
if(br != null){
br.close();
}
}catch(IOException e){
System.out.println(e.getMessage());
}
}
}
これはスタックトレースです:
java.text.ParseException: Unparseable date: "2016/12/19"
at java.text.DateFormat.parse(Unknown Source)
at Model.ProcessDB.getReadTextFile(ProcessDB.java:94)
at View.Dashboard$2.actionPerformed(Dashboard.java:187)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
の
"yyyy/MM/dd"
を使うのか?どの行があなたに「解読不能な日付エラー」を与えていますか? – SMA行は「java.util.Date qDate = format.parse(arr [5]);」です。 – SilverRay
私の問題は、文字列の日付の配列を日付に変換することです。 – SilverRay