NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.highradius.model;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; // mapping,
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fasterxml.jackson.databind.ObjectMapper;
//import com.highradius.model.Prediction;
//@WebServlet("/Predict")
public class Predict extends HttpServlet {

private static final long serialVersionUID = 1L;
private static final Logger LOG = LogManager.getLogger(Predict.class);
/*private static final String SCHEMAURL = "jdbc:mysql://10.1.130.101:3306/1628004";
private static final String USERNAME = "1628004_user";
private static final String PASSWORD = "o7iueOP3KB";*/
private static final String SCHEMAURL = "jdbc:mysql://localhost:3306/1628006";
private static final String USERNAME = "devuser";
private static final String PASSWORD = "Demo@123";
private static final String DRIVERCLASS = "com.mysql.jdbc.Driver";
private Connection dbCon;
private PreparedStatement updateStatement,selectStatement;
private ResultSet result;

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String dueQuery="SELECT due_date FROM acct_doc_hdr WHERE document_id = ? ;";
String updateQuery = "UPDATE acct_doc_hdr SET predicted_payment_date = ? WHERE document_id= ? ;";
ArrayList<String> dates=new ArrayList<>();
try {
Class.forName(DRIVERCLASS);
dbCon = DriverManager.getConnection(SCHEMAURL, USERNAME, PASSWORD);
dbCon.setAutoCommit(false);
selectStatement=dbCon.prepareStatement(dueQuery);
updateStatement=dbCon.prepareStatement(updateQuery);
ObjectMapper mapper = new ObjectMapper();
Prediction[] preds = mapper.readValue(request.getParameter("data"), Prediction[].class);
for(int i = 0; i < preds.length; i++) {
String doc=preds[i].getDocument_id();
String delay=preds[i].getPredictions();
System.out.println("doc,delay: "+doc+","+delay);
selectStatement.setInt(1, Integer.parseInt(doc));
result=selectStatement.executeQuery();
while(result.next()) {
Date date=result.getDate(1);
int d=(int) Math.round(Double.parseDouble(delay));
Calendar c=Calendar.getInstance();
c.setTime(date);
c.add(Calendar.DAY_OF_MONTH, d);
System.out.println("clear: "+c.getTime().toString());
updateStatement.setDate(1, new Date(c.getTimeInMillis()));
updateStatement.setInt(2, Integer.parseInt(doc));
updateStatement.addBatch();
}
}
updateStatement.executeBatch();
dbCon.commit();
updateStatement.clearBatch();
System.out.println("Done");
closeResources();
} catch (Exception e) {
e.printStackTrace();
}

}

private void closeResources() {
closeResource(result);
closeResource(updateStatement);
closeResource(dbCon);
}

private void closeResource(ResultSet rs) {
try {
if (rs != null)
rs.close();
} catch (Exception e) {
System.out.println("Error occurred in closing result set: " + e.toString());
}

}

private void closeResource(Connection dbCon) {
try {
if (dbCon != null)
dbCon.close();
} catch (Exception e) {
System.out.println("Error occurred in closing connection: " + e.toString());
}

}

private void closeResource(PreparedStatement statement) {
try {
if (statement != null)
statement.close();
} catch (Exception e) {
LOG.error("Error occurred in closing statement: " + e.toString());
}
}

}




     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.