Category Archives: J2SE

If Batch Operation failed then Handle all operation separately

package com.raj.db; import java.sql.BatchUpdateException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; class Student{ private int id; private String name; private String queryType; Student(){} Student(int id, String name, String queryType){ … Continue reading

Posted in J2SE | Leave a comment

Get Current Month Name

Calendar cale = Calendar.getInstance(); System.out.println(“Month Name: “+cale.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()));

Posted in J2SE | Leave a comment

Apache DBUtil Create-Insert-Select-Update-Delete program

  public class PlayerData {          private String id;          private String name;          private String team;          private Long totalRuns;          public String getId() … Continue reading

Posted in J2SE | Leave a comment

ENUM vs CONSTANTS

Programs that use the int enum pattern are brittle. Because int enums are compile-time constants, they are compiled into the clients that use them. If the int associated with an enum constant is changed, its clients must be recompiled. If … Continue reading

Posted in J2SE | Leave a comment

JAVA CODE TO CONVERT BYTES TO SUITABLE UNIT

private static DecimalFormat twoDecimalForm = new DecimalFormat(“#.##”); private static final double BYTE = 1024, KB = BYTE, MB = KB*BYTE, GB = MB*BYTE; public static String convertBytesToSuitableUnit(long bytes){ String bytesToSuitableUnit= bytes + ” B”; if(bytes >= GB) { double tempBytes … Continue reading

Posted in J2SE | Leave a comment

JAVA CODE + READ FILE FROM A LAST READ BYTE POSITION OR READ ‘n’ NUMBER OF LINES FROM LAST READ BYTE

public List<Object> retriveMonitorLog(long bytesRead){                             String logFileLocation = “D:/MyLogs.log”;                              RandomAccessFile randomAccess = null;   … Continue reading

Posted in J2SE | Tagged , , , | Leave a comment

JAVA CODE TO EVALUATE THE CONDITION STORED IN STRING VARIABLE

import javax.script.ScriptEngine;import javax.script.ScriptEngineManager; public class TestCondition {    public static void main(String[] bag) throws Exception {                   ScriptEngineManager factory = new ScriptEngineManager();                   ScriptEngine engine … Continue reading

Posted in J2SE | Tagged , , , | Leave a comment