java

[Java] Find a Database table's unique constraint

Hi, I'm trying to find the unique constraints of a table using Java (on an Oracle Database, but that should make no difference). I found a way to discover the Primary Keys of a table, thanks to DatabaseMetaData's getPrimaryKeys(....); However I was unable to find the unique constaints of the tables, and the Internet was not able to he...

HttpServletRequest cannot be resolved can you help?

Hi all I have imported the following import javax.servlet.http.*; I want to get the preferred language Browser HttpServletRequest request = ServletActionContext.getRequest(); Locale userPreferredLocale = request.getLocale(); I get an error HttpServletRequest cannot be resolved. Can somebody help me and give me a step by step instru...

Lifetime management with Google Guice

Is there a recommended pattern for shutting down / closing objects created with Guice? The lifecycle I'm aiming for is: Prepare a Guice Module Create an injector Use the injector through your code to obtain objects (injector.getInstance(Foo.class)) ... Close any resources held by said objects (file handles, TCP connections, etc...). I...

How can I execute the open command via telnet in Java?

Process P = Runtime.getRuntime().exec("cmd /c start telnet"); System.out.println("done running .."); OutputStream output = P.getOutputStream(); BufferedOutputStream out = new BufferedOutputStream(output); String S = "open\n"; byte[] BS = S.getBytes(); out.write(BS); out.close(); The above code is not executing the...

Prevent IllegalStateException when reading from request

I have an interceptor for catching Exceptions and sending emails of this exceptions. All my struts actions extend CoreController which implements SerlvetRequestAware. In mail service class then I have: CoreController cc = (CoreController)invocation.getAction(); HttpServletRequest request = cc.getRequest(); I want to insert request b...

multiple discriminator columns for persistent subclasses

Hello all, I have banged my self with a very particular problem. Using OpenJPA (KODO 4.1) is there a way to use more than one column as a discriminator column? My problem is that i have a table structure (which i have limited ability to modify of course) similar to this: Table VEHICLE EXPENSIVE_CAR CHEAP_CAR EXPENSIVE_BOAT...

Recommended Java frameworks for Google App Engine?

I'm new to google appengine and java webprogramming (jsp/servlets/frameworks) (not to webprogramming or java). I was wondering if appengine supported java frameworks and, if so, which of them are recomandable? Are there any frameworks that support authentication? Thanks ...

Detecting input volume level using Java Sound API

I'm using the Java Sound API to record user speech. I would like to be able to determine when the input volume reaches a certain level (when the user starts speaking) and also when it then retreats back to near silence (when the user stops speaking). This is essentially the same question as this one, however I have discovered that the ...

java heap space and message loss

I'm running a java program on many computers that interact between them. After several hours (2-5 hours) computers start failing (threads start getting into deadlocks, messages start getting lost - peculiar stuff if you take into account that in the first hour or so things were running great). I have a suspicion that it's because I'm us...

Why does Java's Hashtable's get method take an Object as a parameter?

Possible Duplicate: What are the reasons why Map.get(Object key) is not (fully) generic From the JDK Documentation, the put method: public V put(K key, V value) but, the get method: public V get(Object key) Any ideas? Note: In some code I inherited, there is a bug, where someone used a String as a parameter to the get...

java nio Selector wakeup

Please point/provide me an working example of selector.wakeup(); method between two threads. I tried to create a simple program where a thread is waiting on selector.select() method. Second thread creates some sockets and tries to register with the selector; on which the first thread is blocked. Hence I need to use selector's wakeup m...

Self Instantiation in Java

How do I self-instantiate a Java class? I should not use any file other than its class file. Also assume that after the line where I initialized the NAME variable, they don't know the name of the class during compile-time. Example: public class Foo implements Bar { public static final String NAME = "Foo"; private void instanti...

Java z-base-32 encoding algorithm

I'm searching for an implementation of z-base-32 enc algo in java, any suggestions? (encoding and decoding) ...

Removing items from a collection in java while iterating over it

I want to be able to remove multiple elements from a set while I am iterating over it. Initially I hoped that iterators were smart enough for the naive solution below to work. Set<SomeClass> set = new HashSet<SomeClass>(); fillSet(set); Iterator<SomeClass> it = set.iterator(); while (it.hasNext()) { set.removeAll(setOfElementsToRemo...

JPOS Hello World

I would like to print a sample line on my USB POS (Point-Of-Sale) printer from a java program on Windows XP. I tried to setup a JPOS implementation but I get exception after exception for a missing jpos.xml or missing javax.usb.propreties file. Can anyone tell me how to generate thoses files ? They somewhat need to link to an implement...

new to mac.Permission issue with applications

Hellos good fellas! now i'm desparate. I feel like i'm turning round. when i believe solve something then i break something else. started using this mac this week.In the process of setting up my environment i face some challenge.I got a maven project which uses cargo plugin to publish to tomcat working fine.for that i had to google to c...

java: Use of Raw type as method parameter errases all parametrized type information in parameter members.

Please explain me why if I use the raw type A in the method test() , the get() method on my typed list returns an Object and not a B.: public class test { public class B{} public class C{} public class A<T extends C> { private List<B> aBList; public List<B> mGetBList() { return aBLis...

Java, while loop

I am playing with Java and want to do a simple while loop that keeps going until the users does a <ctrl> z. I have something like this public static void main(String[] args) { //declare vars boolean isEvenResult; int num; //create objects Scanner input = new Scanner(System.in); EvenTester app = new EvenTester(...

Java instance variable visibility (ThreadLocal)

In the class ReentrantReadWriteLock is the following curious comment: transient ThreadLocalHoldCounter readHolds; Sync() { readHolds = new ThreadLocalHoldCounter(); setState(getState()); // ensures visibility of readHolds } what does it mean by "ensures visibility"? The reason I ask is that I have a situation where it looks a...

Java: Garbage Collection

I'm having an out of memory error. I have a large range of inputs (2^40), that is too large to hold at once. Each input is a String[]. Instead, I thought I'd run my test program on each input, write the results to a file, then discard the input. The length of the longest input is 42, so that isn't an error causing the overflow. I don't...