• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC error

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried the suggestion but I still get the same error.
Thanks for the help.
Alex Wood
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic