Yes, I also think the problem is the String.
Java Strings do not behave in a Perl-like way, so you can't use the variable
name 'username' directly inside the string. You should use string operators
'+' or 'String.concat(String)' to obtain the same result.

[Andrea Stocco]

DREAMWARE S.r.l.
Multimedia Productions
----------------------------------------
Via Pascoli 19 - 19125 La Spezia - Italy
Tel. ++39 0187 500968   Fax  ++39 0187 516388

Via Caneva 56 - 33013 Gemona del Friuli, Udine - Italy
Tel. ++39 0432 971811   Fax  ++39 0432 971910

----- Original Message -----
From: s saravanan <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, November 16, 2000 1:10 PM
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

Reply via email to