Skip to content

How to catch a specific exception in JDBC?

How to catch specific exceptions in JDBC? Examples: primary key exception or foreign key exception. Answer SQLException contains some database-specific info related to the exception. From the doc: Each SQLException provides several kinds of information: 1) a string describing the error. This is used as the Ja…

Pick a random value from an enum?

If I have an enum like this: What is the best way to pick one randomly? It doesn’t need to be production quality bulletproof, but a fairly even distribution would be nice. I could do something like this But is there a better way? I feel like this is something that’s been solved before. Answer The …

Is there a fixed sized queue which removes excessive elements?

I need a queue with a fixed size. When I add an element and the queue is full, it should automatically remove the oldest element. Is there an existing implementation for this in Java? Answer There is no existing implementation in the Java Language and Runtime. All Queues extend AbstractQueue, and its doc clea…

Listen to a shoutcast with Android

since quite some time I’m trying to listen to .pls files (shoutcasts). I have to say that I failed horrible. Since StreamFurious can do it it must be possible. First I tried to connect to the shoutcast via sockets (TCP and UDP) –> failed. I couldn’t even receive one byte from the server. …

Eclipse debugging “source not found”

I just started using Eclipse so go easy on me ;). But when trying to debug a JUnit test case I get a dialog that states the the source is not found when I get to this line in the code in my test method: I know I should probably go and try and download the source from somewhere, but