java

Java JDBC driver and TYPE_FORWARD_ONLY

Hi, How I could determine if JDBC driver is TYPE_FORWARD_ONLY? In my program the user configures connection parameters to database and he could use any JDBC driver in the class path. I want to know if the driver is TYPE_FORWARD_ONLY before executing any statements. Is this possible? ...

Static methods or Singletons performance-wise (Android)?

In an app with a small number of POJOs and lots of helper methods that operate on them, what's better performance-wise: to make the helper classes singletons or to make the methods static? ...

What are the pros and cons for different methods of checking a Collection for a null before adding to a Set?

This is a follow up question to "Is there a basic Java Set implementation that does not permit nulls?". (thank you to all of those who helped with the answer) It seems that the way to do this, since Sun didn't provide something simple like this OOTB, is with a wrapper / proxy. This seems nearly straight forward. What I am wondering is ...

Where to start? Java application with multiple front ends.

I've got an application here that I wrote many years ago that consists of a heavy-weight front end that directly queries a database server. This application runs on about 7 dedicated workstations. There is also a web-based front-end that I whipped up that shares the same feature set, and a web-based administration too for managing and ...

What am I doing wrong in Java to get this IllegalArgumentException?

I occasionally get an exception in a JTextArea that I'm updating with JTextArea.append() ... java.lang.IllegalArgumentException: Invalid remove at javax.swing.JTextArea.replaceRange(Unknown Source) at sun.plugin.ConsoleWindow$24.run(Unknown Source) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.E...

Best way to learn Java for someone with a solid C++ background? (books, etc.)

I've installed Eclipse and the JDK, gone through the "Hello World" tutorial, and read through the Eclipse docs (both about Eclipse itself and developing Java with Eclipse). I'm looking at the JUnit samples to better understand how Java works when it runs. I'm at that point of confusion one gets when learning a new computer language that...

Spring as a glorified factory; is this acceptable?

I just inherited a Java application and upon inspection of the code, I'm seeing what IMHO is a bastardization of the Spring framework. You see, the Java team seems to have an aversion to interfaces, so we end up with things like this: @Autowired private SomeConcreteFinalClass _myField; There's no Spring configuration, no bean defined...

How to atomically rename a file in Java, even if the dest file already exists?

I have a cluster of machines, each running a Java app. These Java apps need to access a unique resource.txt file concurently. I need to atomically rename a temp.txt file to resource.txt in Java, even if resource.txt already exist. Deleting resource.txt and renaming temp.txt doesn't work, as it's not atomic (it creates a small timefram...

Barcode doesn't display in PDF using iText

I'm using iText to dynamically generate PDF docs. Now I'm trying to dynamically create a barcode in this PDF. Adobe Live Cycle has a barcode function built-in. You can just drag the barcode text box on the page and it's created. Problem: I placed the barcode field in the PDF. Then pass a number to the barcode field from the JSP page. Bu...

exception when parsing multipart form data

I am trying to handle a file upload, and I'm using the com.oreilly.servlet.multipart.MultipartParser class to parse the posted data (in cos.jar). However, when I call the constructor for MultipartParser, I get this exception: java.io.IOException: Corrupt form data: premature ending at com.oreilly.servlet.multipart.MultipartParser.<...

Under what conditions is a JSESSIONID created?

Hi, When / what are the conditions when a JSESSIOINID is created? Is it per a domain? For instance, if I have a Tomcat app server, and I deploy multiple web applications, will a different JSESSIONID be created per context (web application), or is it shared across web applications as long as they are the same domain? ...

Can you view the XML generated by .Net when using a JavaWS service?

Does anyone know how I can view the XML being sent to a Java Web Service from a C# based ASP.NET page? I've created a disco object web ref in .Net from my Java WSDL but when I use the likes of Fiddler to view the XML attached to the HTTP request, instead I see the form parameters being passed. Is there anyway I can view the serialized X...

Viable alternative to XSLT?

I have used XSLT for a few different things over the years. I got used to it, but never felt like I really understood it all the way through. It always seems like I have to experiment to get the result I want, and the outcome isn't necessarily a logical conclusion in hindsight. On top of that, the one or two times I had to turn over som...

adjust selected File to FileFilter in a JFileChooser

I'm writing a diagram editor in java. This app has the option to export to various standard image formats such as .jpg, .png etc. When the user clicks File->Export, you get a JFileChooser which has a number of FileFilters in it, for .jpg, .png etc. Now here is my question: Is there a way to have the extension of the default adjust to t...

Any reason to prefer getClass() over instanceof when generating .equals()?

I'm using Eclipse to generate .equals() and .hashCode(), and there is an option labeled "Use 'instanceof' to compare types". The default is for this option to be unchecked and use .getClass() to compare types. Is there any reason I should prefer .getClass() over instanceof? Without using instanceof: if (obj == null) return false; i...

How do I limit my date range on an Ajax Calendar?

I am using the ajax calendar tool. I like its function, but I would like to restrict the user to an option of selecting a time frame starting with Today, and ending with 6 months prior. How do I do this? ...

JFreechart XYPlot Overlapping Data Artifacts

I am trying to draw some bar graphs with a data set that contains overlapping priorities. E.g. three bars of different colors may be drawn at one point, but the one with the highest priority will be shown. This works most of the time, but I am getting some artifacts on my plot as some of the colors from lower priorities leak through oc...

Generating a maven site including a Cobertura Report

I've got some projects that are already doing site generation via maven, and I want to integrate cobertura reports in them, but no maven goal I seem to run will generate a local preview for me to look at that includes the Cobertura reports in the site. I want to be sure they're generating correctly before I commit the pom changes to the...

Prevent jdbc from padding strings on sql insert and update

We are using the jdbc-odbc bridge to connect to an MS SQL database. When perform inserts or updates, strings are put into the database padded to the length of the database field. Is there any way to turn off this behavior (strings should go into the table without padding)? For reference, we are able to insert field values that don't c...

What's the best way to monitor an InputStream?

I'm reading a file in via apache.commons.FtpClient. This works fine 99.9% of the time but sometimes it just dies in the read() method... InputStream inStream = ftp.retrieveFileStream(path + file.getName()); String fileAsString = ""; if(inStream == null){ return; } while((c = inStream.read()) != -1){ //this is where the code someti...