• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error in servlet

 
ammuswar kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir
i have a table in SQL-SERVER named as title
this table has three fields
1.id
2.tdate----this is of the type datetime
3.content
i am using JRUN 3.0
i want to make a java servlet in which u have a text link
Date todaysdate = new Date();
<a href="localhost:8100/servlet/dateservlet?param = todaysdate">todays content</a>;
In the servlet :
i am accepting this parameter as
String a = request.getParameter("todaysdate");

i will the database connecion---------------------
then
'
select * from title where tdate = 'a';

-----------but this not showing any result
error;
there is something wrong here in he compatitbility of 'a' with tdate
 
Sandeep Jain
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would u mind putting ur code ,Bcoz its pretty difficult to answer why its not working with brief discription .
Need to see the code.
------------------
Try and Try Till u succeed
Sandeep Jain
 
ammuswar kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.Date;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DisplayServlet extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

res.setContentType("text/html");
PrintWriter out = res.getWriter();
Date todaysdate = new Date();
out.print("<html><head>");
out.print("</head><body>");
outprint("<a href="http://localhost:8100/servlet/DisplayServlet?param=todaysdate">Todays content</a>")
//out.print("<form action=\"");
//out.print( req.getRequestURI() );
//out.print("\" method=\"post\">");
//out.print("<input type=\"submit\" ");
//out.print("value=\" \"> ");
//out.print("Display Records</form>");

out.print("</body></html>");
out.close();
}

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

res.setContentType("text/html");
PrintWriter out = res.getWriter();
String a = req.getParameter("param");

out.print("<html><head>");
out.print("</head><body>");
out.print("<code><pre>");




Connection con = null;
Statement stmt = null;
ResultSet rs = null;

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc dbc dbc_exmp,userid,pwd");

stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM title where tdate='a'");


while(rs.next()) {
out.print(rs.getObject(1).toString());
out.print("\t");
out.print(rs.getObject(2).toString());
out.print("\t\t");
out.print(rs.getObject(3).toString());
out.print("\n");
}

} catch (SQLException e) {
throw new
ServletException("Servlet Could not display records.", e);
} catch (ClassNotFoundException e) {
throw new
ServletException("JDBC Driver not found.", e);
} finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt = null;
}
if(con != null) {
con.close();
con = null;
}
} catch (SQLException e) {}
}

out.print("</pre></code>");


out.print("</body></html>");
out.close();
}
}
this is my code---------------------------
now my problem

i have a table in SQL-SERVER named as title
this table has three fields
1.id
2.tdate----this is of the type datetime
3.content
i am using JRUN 3.0
i want to make a java servlet in which u have a text link
Date todaysdate = new Date();
<a href="localhost:8100/servlet/dateservlet?param = todaysdate">todays content</a>;
In the servlet :
i am accepting this parameter as
String a = request.getParameter("param");

i will the database connecion---------------------
then
'
select * from title where tdate = 'a';

-----------but this not showing any result
error;
there is something wrong here in he compatitbility of 'a' with tdate

 
mocca az
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,
Your problem is in your sql statement. You aretrying to get a date that has value of 'a', which will not happen bacause date is stored on form of mm/dd/yy or something like that. What you need to do is concatinate variable in your sql statement. Something like this will probably work for you
rs = stmt.executeQuery("SELECT * FROM title where tdate='" + a + "'");
m, phx
 
mocca az
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to do some serious reading. Continuing working this way will cause you so many problems and may cost you your job or whatever. Path you are following right now will get you nowhere.
 
Kelly So
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think your case is the sql statement that you write.
In my mind in the sql statement, there have one function like
convert(char(10), tdate, 101) or convert(char(11), tdate, 106).....so on. It can convert the date into every format you want. You can find "convert" in your sql help files.
Hope that it can help you a little bit.
Regards,
Kelly
 
ammuswar kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi mocca
u are damn right whatever u said abbt me but the fact of the matter is i have just joined a company where i am seeking desparate job , i am on probabtion period so this task has been given to me to be accomplished but i have scarce knowledge abt java and servlets so i may loose my job also if i dont perform my job so i take whatever help possible from u guys ,
once i get my job somehow i will learn everything and u be credited for this.
i thank u sincerely for whatever help u have given.
i promise i will seek ur advice.
regards
amit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic