// Now because the driver needs to know what the current style is,
// we have to run the following:
st.executeUpdate("show datestyle");
// This is a limitation, but there is no real way around this.
// Now we query the table.
ResultSetrs=st.executeQuery("select dt from datestyle");
// Throw an exception if there is no result (if the table is empty
// there should still be a result).
if(rs==null)
thrownewSQLException("The test query returned no data");
while(rs.next())
{
// The JDBC spec states we should only read each column once.
// In the current implementation of the driver, this is not necessary.
// Here we use this fact to see what the query really returned.
if(standard.equals(rs.getDate(1)))
System.out.println(" passed, returned "+rs.getString(1));
else
System.out.println(" failed, returned "+rs.getString(1));
}
rs.close();
}
}
/**
*Displaysomeinstructionsonhowtoruntheexample
*/
publicstaticvoidinstructions()
{
System.out.println("\nThis example tests the drivers ability to handle dates correctly if the\nbackend is running any of the various date styles that it supports.\nIdealy this should work fine. If it doesn't, then there is something wrong\npossibly in postgresql.Connection or in the backend itself. If this does occur\nthen please email a bug report.\n");
System.out.println("Useage:\n java example.datestyle jdbc:postgresql:database user password [debug]\n\nThe debug field can be anything. It's presence will enable DriverManager's\ndebug trace. Unless you want to see screens of items, don't put anything in\nhere.");
System.exit(1);
}
/**
*Thislittlelotstartsthetest
*/
publicstaticvoidmain(Stringargs[])
{
System.out.println("PostgreSQL datestyle test v6.3 rev 1\n");
if(args.length<3)
instructions();
// This line outputs debug information to stderr. To enable this, simply