java

Convert.ToInt32 versus TryParse

We all know the effects that lots of thrown exceptions can have over the performance of our applications, thus, we should stay away from things like using exceptions for control flow. After this statement I must confess that when coding I didn't care that much about this. I've been working mostly on Java platform but lately I was doing i...

Pagination is not working after search form is submitted and result is shown

Hi, I'm developing a portlet by using Spring. In one of my JSPs I have a form where user can input search parameters ans submit. Both formView and successView is configured to be the same JSP page. In that page, I have a displayTag to render the result. Everything is ok except pagination of the list.My controller(SimpleFormController) ...

Regular expressions in JDBC

I have a java-application using JDBC for database interaction. I want to do a search based on a series of regular-expressions, however the application should be generic, we do not know if the database-engine will by mysql,oracle,sql server etc, but we are pretty sure it's gonna be either mysql or oracle. Will regular-expressions limit m...

Getting unique result in Hibernate

how can we get distinct result by using criteria in hibernate. ...

How to check whether an executable JAR has finished in another JVM

Hi, guys, I encounter a confusing issue! I want to invoke a executable JAR to compute PI from my main java applicaion using runtime.exec(), which create a new JVM for running the executable JAR. My issue is that when the PI computation is done, the JVM is still alive. my main java application has no idea whether PI computation is finishe...

Existing implementations of OSGi Configuration Admin Service?

We are considering to use Configuration Admin Service as a primary API for configuring components in our OSGi-based application. It would be nice if we could reuse some existing implementation so I'm trying to investigate and evaluate the most popular ones. I know there is: Apache Felix Config Admin (org.apache.felix.cm) Equinox Config...

How to enter text in a cross-platform way with the AWT Robot?

The AWT Robot lets you send key press and release events given the keycode of the key you want to press. But the combination of key(s) you need to use to type a character depends on the input locale (e.g. the keyboard layout). We've worked around that by writing our own Keyboard abstraction that maps characters to AWTKeyStrokes and l...

Starting a Java class in different threads

Hi all! I'm wondering how i can call a class from different threads, and have all the calls run in it's own thread? Lets say I have three threads, and each of them need to call anotherClass.getBS(), but the calls might come at the same time, and there's no reason to perform them one at the time. Deadlocks are not a problem. Thanks! ...

hibernate one-to-one or component?

Hi Gurus, I am wondering how to write the model, hbm.xml for table Company ------- id(PK) name address typeid(fk) Type ---- id(PK) type class Company(){ int id; String name; String address; Type type; } class Type(){ int id; String type; } (with get/set methods) How to write the hbm? I am using the hibernate 3.x. ...

Why can't I obtain a FileChannel from a FileWriter ?

Hi, I'm wandering why getChannel is only implemented in FileOutputStream and not in FileWriter. Is there any true reason ? Is there a way to lock a FileWriter another way ? thanks... ...

Memory leak using JNI to retrieve String's value from Java code

i'm using GetStringUTFChars to retrieve a string's value from the java code using JNI and releasing the string using ReleaseStringUTFChars. When the code is run on JRE 1.4 then there is no memory leak but if the same code is run with a JRE 1.5 and higher version then the memory increases. This is a part of the code: msg_id=(*env)->GetS...

Is XML or XUL the future of Java GUI building?

After spending a lot of time and code on programming in Swing, I thought this can't be state-of-the-art Java GUI building. After not finding a user-friendly visual gui bilder for eclipse I stumbled upon declarative GUI building with XML UI toolkits... and I thought: This must be it! I think it's the right way to go, easy and also close t...

SEAM projects run in JBoss AS?

How do I run Seam applications in JBoss AS? I put JBoss SEAM as a dependence (using MAVEN2) of my project and deployed it in JBoss AS - just that will sufice to make my project work properly (with all the features provided by JBoss Seam) or do I need to modify JBoss AS in any way (like, for example, include some extra seam library in th...

J Mock it for Non Static Classes

I have a class under test which says some thing like ClassA a = new ClassA(); In this case, i want it to instantiate ClassB which is a mock of ClassA. I am using Mockit.redefine and restore .. During execution of a.doSomething() I get an error saying java.lang.NoSuchMethodError: ClassB: method ()V not found.. The method signature is ma...

Scheduling Swingworker threads

Hi, I have a 2 processes to perform in my swing application, one to fill a list, and one to do operations on each element on the list. I've just moved the 2 processes into Swingworker threads to stop the GUI locking up while the tasks are performed, and because I will need to do this set of operations to several lists, so concurrency wo...

How do I encrypt a java.util.Properties object (can be any size) using an RSA Public Key?

This is the code I'm currently using. It uses the BouncyCastle Provider. static { Security.addProvider(new BouncyCastleProvider()); } protected String encrypt(byte[] keyData, byte[] data) throws Exception { X509EncodedKeySpec keyspec = new X509EncodedKeySpec(keyData); KeyFactory kf = KeyFactory.getInstance("RSA", "BC"); Pub...

Convert float to double without losing precision

I have a primitive float and I need as a primitive double. Simply casting the float to double gives me weird extra precision. For example: float temp = 14009.35F; System.out.println(Float.toString(temp)); // Prints 14009.35 System.out.println(Double.toString((double)temp)); // Prints 14009.349609375 However, if instead of casting, I o...

Uploading a file to an apache server

I've got a java function that generates digital signatures for xml files. Here's an excerpt that is giving me some trouble: String boundary = MultiPartFormOutputStream.createBoundary(); HttpURLConnection urlConn = (HttpURLConnection)MultiPartFormOutputStream.createConnection(new URL(url + "/sign")); urlConn.setRequestProperty("Accept",...

Ordering coordinates problem (QUESTION FROZEN)

Thanks for all your help on this question but your answers and thoughts have made us think about our problem even more and we cannot agree on what the problem criteria shoudld be - dont put any more answers for now - but watch this space and we will get back to you...Cheers Have been scatching my head about this - and I reckon it's simp...

Testing SQL query on Oracle which includes a remote database

Our development databases (Oracle 9i) use a remote database link to a remote shared database. This decision was made years ago when it wasn't practical to put some of the database schemas on a development machine - they were too big. We have certain schemas on the development machines and we make the remote schemas look local by using ...