If you need to convert from java.util.date to an XMLGregorianCalendar format you can use the following code:
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.datatype.DatatypeConfigurationException;
import java.util.GregorianCalendar;
public class DateConversion {
public XMLGregorianCalendar dateToXMLGregorianCalendar(
final java.util.Date date)
throws DatatypeConfigurationException {
DatatypeFactory df = DatatypeFactory.newInstance();
 if (date == null) {
return null;
} else {
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(date.getTime());
return df.newXMLGregorianCalendar(gc);
}
}
}
Thursday, September 22, 2011
Touch all files within the current directory
If you need to update all files within the current directory with the latest timestamp you can use the following command:
find . -type f -exec touch {} \;
find . -type f -exec touch {} \;
Friday, August 19, 2011
Unmarshal an object using JAXB
The code below can be used to Unmarshal XML that comes in as a String value to an Object (Assuming that JAXB was used to create your classes from the Schema).
String theXMLString = " ... your XML saved as a String value ... ";
MyObject myObject = null;
try {
//"mypackage" is the package where JAXB created the schema classes
final JAXBContext jaxbContext = JAXBContext.newInstance("mypackage");
final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
final ByteArrayInputStream byteStream = new ByteArrayInputStream(theXMLString.getBytes());
myObject = (MyObject) unmarshaller.unmarshal(byteStream);
} catch (JAXBException e) {
System.out.println("An error has occurred: "+e.getMessage(), e);
}
String theXMLString = " ... your XML saved as a String value ... ";
MyObject myObject = null;
try {
//"mypackage" is the package where JAXB created the schema classes
final JAXBContext jaxbContext = JAXBContext.newInstance("mypackage");
final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
final ByteArrayInputStream byteStream = new ByteArrayInputStream(theXMLString.getBytes());
myObject = (MyObject) unmarshaller.unmarshal(byteStream);
} catch (JAXBException e) {
System.out.println("An error has occurred: "+e.getMessage(), e);
}
Monday, July 25, 2011
"No runnable methods" error when doing a Maven install
When doing a maven install I kept getting a Build Failed with this error being generated when attempting to run the test cases:
java.lang.Exception: No runnable methods at
org.junit.internal.runners.TestClassMethodsRunner.testAborted
To solve this problem I first ran a maven clean:
$ mvn clean
and then ran the maven install
$ mvn install
java.lang.Exception: No runnable methods at
org.junit.internal.runners.TestClassMethodsRunner.testAborted
To solve this problem I first ran a maven clean:
$ mvn clean
and then ran the maven install
$ mvn install
Starting up HSQLDB
java -classpath [lib_path]/hsqldb.jar org.hsqldb.Server
Ctrl-C to kill the the Session
Ctrl-C to kill the the Session
Sunday, July 10, 2011
Changing your windows drive on the command prompt
To change your drive from say C:/ to D:/ just do the following:
C:/>d:
D:/>
So all that is required is for you to type in "d:" and press Enter.
C:/>d:
D:/>
So all that is required is for you to type in "d:" and press Enter.
Tuesday, June 7, 2011
Oracle escaping the single quote(') in a select
This query will fail when doing a select statement:
select * from table_name where field='it's friday today';
To escape the single quote (') you need to add in another single quote (''):
select * from table_name where field='it''s friday today';
select * from table_name where field='it's friday today';
To escape the single quote (') you need to add in another single quote (''):
select * from table_name where field='it''s friday today';
Subscribe to:
Posts (Atom)