Hi saravanan,
While forming the query, the string: query="select * from userdet
where uname = username ";
contains the variable username inside the double quotes. This will cause the
database to search for a variable username in the scope of Database and not
in the scope of this Java program. i.e. only after the value of the variable
username is replaced by Java code, the query is elligible for running.
Actually it should be like
query="select * from userdet where uname = ' " + username + " ' ";
I hope the problem will be solved by making this change.
> -----Original Message-----
> From: s saravanan [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, November 16, 2000 5:41 PM
> To: [EMAIL PROTECTED]
> Subject: Retriving datas using odbc-jdbc connection in servlets
>
> Hi All!
>
> I'am learning servlets now for my project. I have some doubts
> regarding the program which i have written:
>
> Here is my program....
> *********************
>
> import java.sql.*;
> import java.io.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class testing extends HttpServlet
> {
>
> public void doPost(HttpServletRequest request, HttpServletResponse
> response)throws
> ServletException, IOException
>
> {
>
> PrintWriter out=response.getWriter();
>
> try
> {
> Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
> Connection con=DriverManager.getConnection("jdbc:odbc:test");
>
> String username=request.getParameter("un");
>
> Statement stmt=con.createStatement();
> String query="select * from userdet where uname = username ";
> ResultSet rs = stmt.executeQuery(query);
>
> while(rs.next())
> {
> out.println(rs.getString(1));
> }
>
>
> out.close();
> }
> catch(Exception e)
> {
> out.println(e);
> }
> }
> }
>
>
> ****
> Here 'test' is the DSN name. I'am using MS-Access as the database. I
> want
> get the first column value in the userdet table by using the uname in the
> where condition.
>
> Actually i'am getting the value in the variable username. That variable
> i
> equated with the uname in the table. But it shows error saying:
>
> java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few
> parameters. Expected 1.
>
>
> If i give like:
> select * from userdet where uname = 'ssarav';
>
> ssarav is the real value in the table. Then it works.
>
> Even if i give like: select * from userdet; This also works.
> But if i give variable name with the equated symbol , it does not work
> saying the above error.
>
> Please help me what to do....
>
> Bye,
> s.saravanan,
> web programmer,
> Alpha Systems,
> email-id: [EMAIL PROTECTED]
>
>
>
>
>
>
>
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
> Share information about yourself, create your own public profile at
> http://profiles.msn.com.
>
> __________________________________________________________________________
> _
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html