I have below a segment of the code I have. Please see:
Workload workload;
ArrayList<Workload> workList = null;
System.out.print("first");
try{
System.out.print("first");
ConnectionFactory myFactory = ConnectionFactory.getFactory();
Connection conn = myFactory.getConnection();
int i = 0;
PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM WORKLOAD WHERE datestart LIKE '? %'");
PreparedStatement pstmtMember = conn.prepareStatement("SELECT * FROM MEMBER WHERE memberid = ? and deletestatus = 0");
PreparedStatement pstmtLeader = conn.prepareStatement("SELECT * FROM LEADER WHERE leaderid = ? and deletestatus = 0");
pstmt.setString(i++, startdate);
ResultSet rs = pstmt.executeQuery();
workList = new ArrayList<Workload>();
My problem with the code is that it “goes out” once it reaches the pstmt.setString part.
The reason why i put a LIKE ‘? %’ is because I needed to get only the date in from the query. Not the whole time stamp. Basically it disregards what comes after putting a date like ‘2012-04-05’.
You can’t put the single quotes around it like that you can only treat the ? like it was a variable written in a procedure
That is the equivalent of what you wrote.
The following will only work if the date is stored in a character field
If the datatype on datestart in the database is datetime you will need to do something like this respective to your database platform (this is sql server). Only replacing that individual prepareStatement line.