In order to make our code more usable. here I try to take many pattern but didn't get my results
I am however facing a problem with the date variable , If I pass static variable then it's right output. but I want to dynamic(user input date). I don't to pass predefine date.
Pls give me proper solution.
Here is the code:
Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:VASVMT","scott","tiger");
Statement stmt=con.createStatement();
Scanner sc=new Scanner(System.in);
System.out.println("Enter DOB (dd-mm-yyyy) format");
String td=sc.next();
SimpleDateFormat date1=new SimpleDateFormat("dd-MM-yyyy");
System.out.println(date1);
java.util.Date tdd=date1.parse(td);
System.out.println(tdd);
long ms=tdd.getTime();
System.out.println(ms);
java.sql.Date dttt=new java.sql.Date(ms);
System.out.println(dttt);
String sql="select * from tbl_transaction_new where to_char(date_time,'dd-mm-yyyy')='dttt'";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
System.out.print(" NAME: "+rs.getString("messgae"));
System.out.print(" Date: "+rs.getDate("date_time"));
System.out.println();
con.close();
}
My sql table -- Like
message(column) and date_time(column, datatype- Date).. In date_time column values are like 05-JUL-2021 , 08-JUL-2021 , 01-JAN-2021.