Category: Java

Uploading a CSV to a REST web service

import org.apache.http.client.methods.*; import org.apache.http.client.*; import org.apache.http.impl.client.*; import org.apache.http.*; import org.apache.http.entity.mime.*; import org.apache.http.entity.*; import java.io.*; public class API_H01 { public static void main (String args[]) { try { HttpClient client = HttpClientBuilder.create().build(); File f = new File(“/opt/tomcat8/hierarchy.csv”); MultipartEntityBuilder builder = MultipartEntityBuilder.create();…

java dynamic SQL formatter

import java.sql.*; public class dynColumns { public static void main(String[] args) { try { Connection con = DriverManager.getConnection(“jdbc:oracle:thin:” + args[0]); Statement stm = con.createStatement(); ResultSet rst = stm.executeQuery(args[1]); ResultSetMetaData rstMeta = rst.getMetaData(); int columns = rstMeta.getColumnCount(); while (rst.next()) { for…

Does BlockingQueue.take() use CPU?

No… [root@cmhlcarchapp01 ~]# cat t.java import java.util.concurrent.*; public class t implements Runnable { static ArrayBlockingQueue Q = new ArrayBlockingQueue(5); String type; public static void main (String args[]) { t n = new t(“producer”); t n2 = new t(“consumer”); } public…

DNS server address cached in java?

We found that an old DNS address was used until we restarted the JVM. I need to review the class used to perform this activity.. Test this with a simple class. import java.net.*; public class test { static { java.security.Security.setProperty…

Simulating SocketTimeoutException

A SocketTimeoutException occurs when a socket object instance has been configured to throw the exception if it receives no data in the prescribed number of milliseconds. The default is 0, which disables the timeout. Reasons you may want to use…

Connection Reset – What does it mean?

Generally, it indicates your client successfully connected to the server. A subsequent attempt to use the client connection failed after the server closed the socket, or had been disconnected for any reason. You can prove this with what is below,…