I am getting the following error...java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2. This is the code... import java.sql.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Test1 extends HttpServlet { String dBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; Connection dbConnection; Statement sQLStatement; String url = "jdbc dbc:Project"; String username = ""; String password = ""; ResultSet rs; public void init( ServletConfig config ) throws ServletException { super.init( config ); try { Class.forName( dBDriver ).newInstance(); dbConnection = DriverManager.getConnection( url, username, password); sQLStatement = dbConnection.createStatement(); } catch (Exception e ) { e.printStackTrace(); } } public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { String document; document = "<HTML><HEAD><TITLE>\n" + "Project test\n" + "</TITLE></HEAD><BODY>\n" + "<H1>Well at least this part works</H1>\n" + "/Fields\n" + "[\n" + "<<\n"+ "/T (Namefield)\n"+ "</BODY></HTML>"; rs = sQLStatement.executeQuery(
"SELECT Test.Value FROM Projectdata WHERE Test.Field='FirstName'"); while( rs.next() ) document += "/V (" + rs.getString( "Value" ) + ")\n"; response.setContentType("text/html"); PrintWriter out = new PrintWriter(response.getOutputStream()); out.println(document); out.close(); } catch( IOException e ) { response.setContentType("text/html"); PrintWriter out = new PrintWriter(response.getOutputStream()); out.println( e.toString() ); out.close(); } catch(SQLException e ) { response.setContentType("text/html"); PrintWriter out = new PrintWriter(response.getOutputStream()); out.println( e.toString() ); out.close(); } } } Anyone have any ideas what the problem is? Thanks. Alex
kim jungil
Greenhorn
Joined: Sep 27, 2001
Posts: 27
posted
0
"SELECT Test.Value FROM Projectdata WHERE Test.Field='FirstName'"); while( rs.next() ) document += "/V (" + rs.getString( "Value" ) + ")\n"; I think the fourth line is error. you must write rs.getString( "Test.Value" ), because you write the query language, you select Test.Value, not Value.
Alex Wood
Greenhorn
Joined: Aug 15, 2001
Posts: 3
posted
0
I tried the suggestion but I still get the same error. Thanks for the help. Alex Wood
Adam Hardy
Ranch Hand
Joined: Oct 09, 2001
Posts: 564
posted
0
alex, does it give this error when you execute the same sql string in the access database? also, i'm not sure about this but i don't think you should use VALUE and FIELD as the names of fields. adam
I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.