すべてのレコードの完全な日付を取得できますが、各レコードの日のみを取得したいと思います。たとえば、日付が2017-01-20ですが、取得したいのは20だけです。どうすればよいですか。これが私のコードです:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String date = sdf.format(calendar.getDate());
String sql = "SELECT reserve_date FROM reservation";
try
{
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
text.setText("");
while(rs.next()){
String str = rs.getString("reserve_date");
text.append(str);
text.append("\n");
}
pst.close();
rs.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
finally{
try{
rs.close();
pst.close();
}catch(Exception e){JOptionPane.showMessageDialog(null, e);}
}
次のDAYOFMONTH
ようなMySQL関数を使用できます
String sql = "SELECT DAYOFMONTH(reserve_date) FROM reservation";
そしてどちらか
String str = rs.getString(1);
または
int dayOfMonth = rs.getInt(1);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加