Thursday, May 31, 2012

len length

Microsoft SQL Server has a function called len() while MySQL has a function called length().

There doesn't seem to be any common way to write SQL that will work in both servers.  So I guess my Java program will have to resort to detecting the server type from a JDBC Connection and making the necessarily adjustments to the queries.

Connection con;
DatabaseMetaData databaseMetaData;
...
databaseMetaData = con.getMetaData();
if (databaseMetaData.getDatabaseProductName().contains("Microsoft"))
{
  /*
   * SQL Server, boo!
   */
}
else
{
  /*
   * MySQL, hotdog!
   */
}

For what it's worth SQL Server appears to be the out-of-spec one of the two (shocking I know).

No comments:

Post a Comment