📄 msqlhelper.java
字号:
package org.dbgen.support;import java.sql.Date;import java.sql.Time;import java.sql.Timestamp;import java.text.SimpleDateFormat;/** * The MsqlHelper classes provide basic support for Date and Time * handling on MSQL databases. The design of this class is largely * based on the method described in the PROGRAMMING documentation * from the mSQL-JDBC driver. * * The mSQL-JDBC driver is available from http://www.imaginary.com/. * */public class MsqlHelper { public final static int DATE_AS_LONG = 1; public final static int DATE_AS_STRING = 2; public final static int TIME_AS_LONG = 3; public final static int TIME_AS_STRING = 4; protected static int dateHandling = DATE_AS_STRING; protected static int timeHandling = TIME_AS_STRING; /** * Format a Date object for use in a SQL statement. * @return The textual representation of the Date object. * @param t The Date object. */ public static String formatDate(Date t) { if (dateHandling == DATE_AS_LONG) { return "" + t.getTime(); } else { SimpleDateFormat sf1 = new SimpleDateFormat("MMM"); SimpleDateFormat sf2 = new SimpleDateFormat("dd-"); SimpleDateFormat sf3 = new SimpleDateFormat("-yyyy"); return sf2.format(t) + sf1.format(t).substring(0, 3) + sf3.format(t); } } /** * Format a Time object for use in a SQL statement. * @return The textual representation of the Time object. * @param t The Time object. */ public static String formatTime(Time t) { if (timeHandling == TIME_AS_LONG) { return "" + t.getTime(); } else { SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss"); return sf.format(t); } } /** * Format a Timestamp object for use in a SQL statement. * @return The textual representation of the Timestamp object as a Long value. * @param t The Timestamp object. */ public static String formatTimestamp(Timestamp t) { return "" + t.getTime(); } /** * Set the date handling method. * @param method Either DATE_AS_LONG or DATE_AS_STRING. */ public static void setDateHandling(int method) { dateHandling = method; return; } /** * Set the time handling method. * @param method Either TIME_AS_LONG or TIME_AS_STRING. */ public static void setTimeHandling(int method) { timeHandling = method; return; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -