java

What is the best-practice for nesting PreparedStatements?

I have several instances where that a section of legacy sql statements is based on a dependency. for example. if (x !=null) { SQL = "SELECT z WHERE x > y"; } else { SQL = "SELECT z WHERE x <= y"; } SQL2 = SQL + " JOIN a ON b"; I am creating PreparedStatements out of this legacy code. What is the best-practice here. Should I cre...

Message processing with priorities

In a Java web application I have a recurring message load of type A (e.g., 20,000 every hour). Then I have a second type of messages (type B) that show up occasionally but have a higher priority than type A (say, 3,000). I want to be able to process these messages on one or more machines using open source software. It seems to me that...

Why can't the Java compiler figure this out?

Why is the compiler unable to infer the correct type for the result from Collections.emptySet() in the following example? import java.util.*; import java.io.*; public class Test { public interface Option<A> { public <B> B option(B b, F<A,B> f); } public interface F<A,B> { public B f(A a); } public ...

PNG TrayIcon transparency on Windows

I'm trying to use a transparent PNG as the icon for my Java application. The image on the JFrame and task bar work great. However, when I use the image with a TrayIcon, I get a black matte background around the edge of the PNG. Has anybody else come across this issue? I would really like to use a PNG instead of GIF or JPEG. ...

How to map many-to-many List in Hibernate with a Link Table

I would like to map a many-to-many in Hibernate using a link table. I have two classes, Parent and Child class, for example: public class Parent{ private List<Child> _children; //...getters and setters } I use a link table (link_table) with three columns link_id, parent_id, and child_id. The database is SQL server and id types are u...

JPA cascade options at runtime

I'm trying to make an application that keeps an object model in sync with a database by observing all changes and then immediately persisting the objects in questions. Many of the object in the model have children in large lists or trees. When I load an object from the database, I rely on a one-way cascading relationship to also retrie...

Tomcat 6 Default Buffer Size

Is there a way to set the default buffer size for JSPs in Tomcat? I know I can set them on every page, but am hoping there's a global option somewhere. ...

Uniquely identify an instance of a JSR-168 portlet

I am writing a JSR-168 portlet that can be added to a container multiple times. Each container (Liferay, JBoss, etc.) has its own internal way of differentiating between multiple instantiations of the same portlet. I, however, would like to uniquely identify my portlet instance inside the doView() method itself. Is there any standard, ...

show the value of the graph when cursor is placed on the graph

Hi, I am using jfreechart to draw the graphs. I need to show the value when the cursor is placed on the graph. Thanks in advance ...

Why is Java's Cloneable Interface Not Generic?

Java 5 introduced generics, and they were added to many interfaces in the java.lang package. However, Cloneable did not get generics. I wonder why? Edit: In reply to the answers of @Jon and @litb, and the comment of @Earwicker, I was thinking Cloneable might be: public interface Cloneable<T> { public T clone(); } Here T clone()...

Padding Strings in Java

Is there some easy way to pad Strings in Java. seems like something that should be in some stringUtil like api but i cant find any. ...

Is Java the best language to develop cross-platform GUI applications?

For "best" I intend that the code shouldn't need, or need very few, platform specific tweaks. ...

Netbeans intellisense for Yahoo utils

In netbeans I created an html page in which I am using Yahoo utils. If I type "yahoo." then namespace, render, hide are not visible in the interactive documentation. Please tell me how to configure Netbeans to handle this. ...

What are some good libraries for graph processing / task scheduling

I'm working on (yet another) to do list program, and part of the problem I want to solve is capturing task dependencies and relative importance. I'm interested in recommendations for libraries / component that help with: Graph processing (including PageRank-like algorithms) Task / project scheduling - edit: note I don't mean OS proc...

Can my build stipulate that my code coverage never get worse?

I am using hudson CI to manage a straight java web project, using ant to build. I would like to mandate that the unit test coverage never be worse than the previous build, thereby making sure any new code is always tested, or at least the coverage is continually improving. Is there a hudson plugin that works this way? Edit: I am curre...

Continue keyword in Java

I saw this keyword for the first time and I was wondering if some one could explain to me what it does. The situation in which I saw the keyword was: if(obj.isFlagSet()) ; else continue; I can't seem to figure out what the continue is doing. ...

LDAP Java library

We are using J2EE to develop a security product that relies on LDAP for authentication and role-based user management. The team has implemented this using the JNDI but we have run into various pitfalls. I am looking for an LDAP API that handles all the low-level details and satisfies the following requirements: LDAP User authenticatio...

How to use ImageIO to save multiple BufferedImages to a file

I tried both of the following options: <1> BufferedImage Buffered_Image; MemoryCacheImageOutputStream MemoryCache_OutputStream=new MemoryCacheImageOutputStream(new FileOutputStream("C:/Test.mov",false)); while (notFinished) // Main recording loop. { Buffered_Image=robot.createScreenCapture(); // Capture Screen image. tr...

Java Statement Object Reuse?

I would like to know if we can reuse the same Statement object for executing more than one query. Or, should we create a new statement for different queries. For example, Connection con = getDBConnection(); Statement st1 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); int i = st1.executeUpdate("updat...

Logging Commons and Mapped Diagnostic Context

What have others done to get around the fact that the Commons Logging project (for both .NET and Java) do not support Mapped or Nested Diagnostic Contexts as far as I know? ...