Skip to content

Instantly share code, notes, and snippets.

@mherman22
Created March 10, 2022 12:32
Show Gist options
  • Select an option

  • Save mherman22/68bf5d771e039ea96c6ab31051075379 to your computer and use it in GitHub Desktop.

Select an option

Save mherman22/68bf5d771e039ea96c6ab31051075379 to your computer and use it in GitHub Desktop.
just for keeps
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class JsonToDatabase {
public static void databaseQuery() throws Exception {
JSONParser jsonParser = new JSONParser();
try {
// JSONObject jsonObject = (JSONObject) jsonParser.parse(new FileReader("C:/Users/HERMAN MUHEREZA/Documents/Batch057/new.txt"));
// JSONArray jsonArray = (JSONArray) jsonObject.get("new");
Connection con = DatabaseConnectivity.ConnectToDB();
PreparedStatement pstmt = con.prepareStatement("INSERT INTO infotable values (?, ?, ?, ?, ?, ? )");
for (Object object : jsonArray) {
JSONObject record = (JSONObject) object;
int infoFileId = Integer.parseInt((String) record.get("infoFile_id"));
String batchErrorstate = (String) record.get("batchErrorstate");
String batchLastAccessedDocument = (String) record.get("batchLastAccessedDocument");
String batchNextDocId = (String) record.get("batchNextDocId");
String batchNextPagId = (String) record.get("batchNextPagId");
String batchState = (String) record.get("batchState");
String key = (String) record.get("key");
String batchLocked = (String) record.get("batchLocked");
String batchNoOCRImageSize = (String) record.get("batchNoOCRImageSize");
String batchBacksRescanned = (String) record.get("batchBacksRescanned");
String batchCreatedUserID = (String) record.get("batchCreatedUserID");
String batchImageCountGrayscale = (String) record.get("batchImageCountGrayscale");
String batchImageCountGrayscaleBack = (String) record.get("batchImageCountGrayscaleBack");
String batchModifiedDatetime = (String) record.get("batchModifiedDatetime");
String batchFrontsCaptured = (String) record.get("batchFrontsCaptured");
String batchBacksCaptured = (String) record.get("batchBacksCaptured");
String batchBacksDeleted = (String) record.get("batchBacksDeleted");
String batchCreatedDatetime = (String) record.get("batchCreatedDatetime");
String batchIndex0005 = (String) record.get("batchIndex0005");
String batchModifiedUserID = (String) record.get("batchModifiedUserID");
String batchOutputStartDatetime = (String) record.get("batchOutputStartDatetime");
String batchImageAddress = (String) record.get("batchImageAddress");
String batchImageCountBlackWhiteFront = (String) record.get("batchImageCountBlackWhiteFront");
String batchImageCountColorFront = (String) record.get("batchImageCountColorFront");
String batchIndex0006 = (String) record.get("batchIndex0006");
String batchModifiedWorkstationID = (String) record.get("batchModifiedWorkstationID");
String batchPageCount = (String) record.get("batchPageCount");
String batchBacksRemoved = (String) record.get("batchBacksRemoved");
String batchFirstDocumentID = (String) record.get("batchFirstDocumentID");
String batchImageCountBlackWhiteBack = (String) record.get("batchImageCountBlackWhiteBack");
String batchImageCountColor = (String) record.get("batchImageCountColor");
String batchImageCountColorBack = (String) record.get("batchImageCountColorBack");
String batchImageCountGrayscaleFront = (String) record.get("batchImageCountGrayscaleFront");
String batchModifiedWorkstationName = (String) record.get("batchModifiedWorkstationName");
String batchStartingDocumentID = (String) record.get("batchStartingDocumentID");
String batchCreatedWorkstationID = (String) record.get("batchCreatedWorkstationID");
String batchDocumentCount = (String) record.get("batchDocumentCount");
String batchImageCountBlackWhite = (String) record.get("batchImageCountBlackWhite");
String batchLastDocumentID = (String) record.get("batchLastDocumentID");
String batchIndex0001 = (String) record.get("batchIndex0001");
String batchLocation = (String) record.get("batchLocation");
String batchOutputUserID = (String) record.get("batchOutputUserID");
String batchSizeOfImages = (String) record.get("batchSizeOfImages");
String batchCreatedWorkstationName = (String) record.get("batchCreatedWorkstationName");
String batchImageCount = (String) record.get("batchImageCount");
String batchIndex0002 = (String) record.get("batchIndex0002");
String batchOutputServerAddress = (String) record.get("batchOutputServerAddress");
String batchOutputWorkstationID = (String) record.get("batchOutputWorkstationID");
String batchFrontsDeleted = (String) record.get("batchFrontsDeleted");
String batchFrontsRescanned = (String) record.get("batchFrontsRescanned");
String batchIndex0003 = (String) record.get("batchIndex0003");
String batchOutputWorkstationName = (String) record.get("batchOutputWorkstationName");
String batchFrontsRemoved = (String) record.get("batchFrontsRemoved");
String batchIndex0004 = (String) record.get("batchIndex0004");
// String batchImageCountBlackWhite = (String) record.get("batchImageCountBlackWhite");
pstmt.setInt(1, infoFileId);
pstmt.setString(2, batchCreatedUserID);
pstmt.setString(3, batchCreatedDatetime);
pstmt.setString(4, batchModifiedUserID);
pstmt.setString(5, batchModifiedWorkstationID);
pstmt.setString(6, batchLocation);
pstmt.setString(7, batchModifiedWorkstationName);
pstmt.setString(8, batchErrorstate);
pstmt.setString(9, batchIndex0004);
pstmt.setString(10, batchOutputWorkstationName);
pstmt.setString(11, batchFrontsRemoved);
pstmt.setString(12, batchIndex0003);
pstmt.setString(13, batchFrontsRescanned);
pstmt.setString(14, batchFrontsDeleted);
pstmt.setString(15, batchOutputWorkstationID);
pstmt.setString(16, batchOutputServerAddress);
pstmt.setString(17, batchIndex0002);
pstmt.setString(18, batchImageCount);
pstmt.setString(19, batchCreatedWorkstationName);
pstmt.setString(20, batchSizeOfImages);
pstmt.setString(21, batchOutputUserID);
pstmt.setString(22, batchIndex0001);
pstmt.setString(23, batchLastDocumentID);
pstmt.setString(24, batchImageCountBlackWhite);
pstmt.setString(25, batchCreatedWorkstationID);
pstmt.setString(26, batchDocumentCount);
pstmt.setString(27, batchStartingDocumentID);
pstmt.setString(28, batchImageCountGrayscaleFront);
pstmt.setString(29, batchImageCountColorBack);
pstmt.setString(30, batchImageCountColor);
pstmt.setString(31, batchImageCountBlackWhiteBack);
pstmt.setString(32, batchBacksRemoved);
pstmt.setString(33, batchFirstDocumentID);
pstmt.setString(34, batchIndex0006);
pstmt.setString(35, batchImageCountColorFront);
pstmt.setString(36, batchImageCountBlackWhiteFront);
pstmt.setString(37, batchImageAddress);
pstmt.setString(38, batchLastAccessedDocument);
pstmt.setString(39, batchNextDocId);
pstmt.setString(40, batchNextPagId);
pstmt.setString(41, batchState);
pstmt.setString(42, key);
pstmt.setString(43, batchLocked);
pstmt.setString(44, batchNoOCRImageSize);
pstmt.setString(45, batchBacksRescanned);
pstmt.setString(46, batchImageCountGrayscale);
pstmt.setString(47, batchImageCountGrayscaleBack);
pstmt.setString(48, batchFrontsCaptured);
pstmt.setString(49, batchModifiedDatetime);
pstmt.setString(50, batchBacksCaptured);
pstmt.setString(51, batchBacksDeleted);
pstmt.setString(52, batchIndex0005);
pstmt.setString(53, batchOutputStartDatetime);
pstmt.setString(54, batchPageCount);
pstmt.executeQuery();
}
} catch (IOException io) {
io.printStackTrace();
}
}
}
@mherman22
Copy link
Author

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class WatchFolder {

	public static void main(String args[]) throws Exception {	
		// watchFolder();
		//		JsonToDatabase.databaseQuery();


		BufferedReader reader;
		try {
			reader = new BufferedReader(new FileReader("/C:/Users/HERMAN MUHEREZA/Documents/Batch057/info"));
			String line = reader.readLine();
			String lineArray [] ;

			String infoFile_id,
			batchErrorstate,
			batchLastAccessedDocument,
			batchNextDocId,batchNextPagId,
			batchState,key = "",
			batchLocked,batchNoOCRImageSize,
			batchBacksRescanned,batchCreatedUserID,
			batchImageCountGrayscale,
			batchImageCountGrayscaleBack,
			batchModifiedDatetime,
			batchFrontsCaptured,
			batchBacksCaptured,
			batchBacksDeleted,
			batchCreatedDatetime,
			batchIndex0005,
			batchModifiedUserID = "",
			batchOutputStartDatetime,
			batchImageAddress,
			batchImageCountBlackWhiteFront,
			batchImageCountColorFront,
			batchIndex0006,
			batchModifiedWorkstationID,
			batchPageCount,
			batchBacksRemoved,
			batchFirstDocumentID,
			batchImageCountBlackWhiteBack,
			batchImageCountColor,
			batchImageCountColorBack,
			batchImageCountGrayscaleFront,
			batchModifiedWorkstationName,
			batchStartingDocumentID,
			batchCreatedWorkstationID,
			batchDocumentCount,
			batchImageCountBlackWhite,
			batchLastDocumentID,
			batchIndex0001,
			batchLocation,
			batchOutputUserID,
			batchSizeOfImages,
			batchCreatedWorkstationName,
			batchImageCount,
			batchIndex0002,
			batchOutputServerAddress,
			batchOutputWorkstationID,
			batchFrontsDeleted,
			batchFrontsRescanned,
			batchIndex0003,
			batchOutputWorkstationName,
			batchFrontsRemoved,
			batchIndex0004 = "";

			String infoFromfile="",
					results="";

			while (line != null) {
				lineArray = line.split("=");
				//	System.out.println(lineArray.length);
//				infoFromfile="";
				infoFromfile=lineArray[0].trim();
//				results ="";
				if(lineArray.length==2) {
					results = lineArray[1];

				}
				System.out.println(infoFromfile);
				System.out.println(results);
//				if(infoFromfile=="batch.errorstate"){
//
//					batchErrorstate = results;
//				}
//				if(infoFromfile.equalsIgnoreCase("key")){
//
//					key = results;
//					System.out.println("<-----Found->");
//				}



				System.out.println("<------------------------>");
				// read next line
				line = reader.readLine();

			}
			reader.close();

			//			System.out.println("key "+key);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void watchFolder() {
		FolderMonitor.fileMonitor();	
	}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment