Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa SQL date problem in sql server

Have Programming Question? Ask it here!
 
 
 


pradeep
date problem in sql server
1 Answer(s)      4 years and 5 months ago
Posted in : SQL


select count(*) from xxxx_tbl where emplid="+emplid+" and work_dt=#"+work_date+"#"; work_date is in string ,Backend is sql server 2000.i am getting the date problem when using in jsp page.

Advertisement
View Answers

March 31, 2010 at 12:06 PM


Hi Friend,

Try the following code:

retrieveDate.jsp:

<%@page import="java.sql.*"%>
<form method="post" action="retrieveDate.jsp">
<table>
<tr><td>ID</td><td><input type="text" name="id"></td></tr>
<tr><td>Work Date(yyyy-MM-dd)</td><td><input type="text" name="d"></td></tr>
<tr><td><input type="submit" value="Submit"></td></tr>
</table>


<%
String ide=request.getParameter("id");
String date=request.getParameter("d");


String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/test";;

String GET_RECORD = "select count(*) from d where id='"+ide+"' and myDate='"+date+"'";
ResultSet rs = null;
Connection conn = null;
Statement stmt = null;
try {
Class.forName(driver);
conn=DriverManager.getConnection(url, "root", "root");

stmt = conn.createStatement();
rs = stmt.executeQuery(GET_RECORD);
while (rs.next()) {
out.println("Count =" + rs.getString("count(*)"));
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
%>

Thanks


Related Tutorials/Questions & Answers:
 

 

 

DMCA.com