public static void main(String[] args) {
LocalDateTime dateTime = LocalDateTime.now(); // 获取当前日期时间
int year = dateTime.getYear(); // 获取当前年份
int month = dateTime.getMonthValue(); // 获取当前月份
int day = dateTime.getDayOfMonth(); // 获取当前日期
int hour = dateTime.getHour(); // 获取当前小时
int minute = dateTime.getMinute(); // 获取当前分钟
int second = dateTime.getSecond(); // 获取当前秒数
System.out.println("当前年份:" + year);
System.out.println("当前月份:" + month);
System.out.println("当前日期:" + day);
String dateStr = String.format("%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second);
System.out.println("当前日期时间:" + dateStr);
}
不知道你这个问题是否已经解决, 如果还没有解决的话:public static void main(String[] args) {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/ishopn?characterEncoding=utf8"; //url jdbc有自己的写法 jdbc:oracl
String user="root";
String password="1234";
conn = DriverManager.getConnection(url, user, password);
/*
* // String cu_name="' or 1=1 #"; // String cu_phone="dadadadad";
*
* String cu_name="刘德华"; String cu_phone="7777";
*
* String sql = "select count(*) from customer where cu_name=? and cu_phone=?";
*
* PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, cu_name);
* ps.setString(2, cu_phone);
*
* ResultSet rs = ps.executeQuery(); rs.next();
* System.out.println(rs.getInt(1));
*/
// update该刘德华的密码 7777 -> 9999
String cu_id = "2a4e0cdd-380e-41bf-960f-f2f6d0a6ccae";
String cu_phone="9999";
String sql = "update customer set cu_phone=? where cu_id=?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, cu_phone);
ps.setString(2, cu_id);
int line = ps.executeUpdate();
System.out.println(line);
}catch(Exception e) {
e.printStackTrace();
}finally {
if(conn!=null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
很多种写法 看你们要求用哪种来练习了