我写的用sql语句取时间,可老报驱动有问题,下面的话:
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriverj
va.lang.NullPointerException
叫我好恼心呀!
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriverj
va.lang.NullPointerException
叫我好恼心呀!
还有System.currentTimeMillis()返回的是一个以毫秒生成的long数字,你到底要实现什么样的功能,把代码片断贴点出来.
Timestamp today=new Timestamp(cal.getTimeInMillis());
System.out.println(today);orDate today=new Date();
System.out.println(today);
format = "yyyy-MM-dd hh:mm:ss"; Sql = "select getdate() as serverTime"; try {
stmt = cnn.createStatement();
rs = stmt.executeQuery(Sql);
if (rs.next())
return new SimpleDateFormat(format).format(rs
.getTimestamp("serverTime"));
else
throw new SQLException();
} catch (SQLException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null, "获取系统时间时发生错误,请与管理员联系!", "错误",
JOptionPane.ERROR_MESSAGE);
DBConnection.logoff();
return null;
}
}
我想楼主的意思是获取服务器时间吧,本地时间获取有个鬼用啊,右下角看一眼不就知道了,用我的吧,不但能获取时间,还能格式化成你想要的格式
变量自己定义一下,再引入包,再把我这个程序copy过去,直接可以用了