Skip to content

How to start a transaction in JDBC?

Connection.setTransactionIsolation(int) warns: Note: If this method is called during a transaction, the result is implementation-defined. This bring up the question: how do you begin a transaction in JDBC? It’s clear how to end a transaction, but not how to begin it. If a Connection starts inside in a t…

Moving items around in an ArrayList

I’ve been playing around with ArrayLists. What I’m trying to achieve is a method to do something like this: I’m trying to be able to move items up in the list, unless it is already at the top in which case it will stay the same. For example, if item 3 was moved the list would be: From my sma…

Removing all whitespace characters except for ” “

I consider myself pretty good with Regular Expressions, but this one is appearing to be surprisingly tricky: I want to trim all whitespace, except the space character: ‘ ‘. In Java, the RegEx I have tried is: [s-[ ]], but this one also strips out ‘ ‘. UPDATE: Here is the particular str…

Executing helloworld.java in apache hadoop

can someone pls tell me how can i execute my HelloWorld.java in apache hadoop which contains class Helloworld { public static void main(String[] args) { Sytem.out.println(“…

Get the indices of an array after sorting?

Suppose the user enter an array, for example: which I did know the length of it the index array would be: Now, after sorting it using Arrays.sort(Array); newArray will be like: and the newIndex will be: The problem is: how can I find the newIndex from the input Array? Answer Don’t sort the array to star…