• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

JDBC & Servlet

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear friends ,
i'm using JDBC connectivity in the HttpServlet . Here is my query for
executeQuery as a parameter invoked by statement object,
Select Promotion_Date from Promotion where Emp_Code = a4
but after this statement i get error message as given below,
ERROR:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
can anybody help me out ? Thanx in advance !
from ,
vikram .
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vikram,
Please post the code where you are experiencing this problem.
Regards,
Milind
 
Vikram Deshmukh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a code to ease the Qn.
all req imports
public class Selection extends HttpServlet
{
Connection con;
Statement stmt;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
// initializing database drivers
String driverName,url,user,password;
Driver driver;
try
{
driverName = "sun.jdbc.odbc.JdbcOdbcDriver";//using JdbcOdbc bridge
driver = (Driver)Class.forName(driverName).newInstance();// registering driver
url = "jdbc dbc:Promo"; // Data Source Name
user = "";
password = "";
con = DriverManager.getConnection(url,user,password);
stmt = con.createStatement();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws IOException, ServletException
{
String chbxeCode = new String();
String chbxproDate = new String();
String chbxproPost = new String();
String query = new String();
String str = null;
boolean flag = false;
String eCode = null;
String ePromoDate = null;
String ePromoPost = null;
Object obj = null;
PrintWriter pw = null;
res.setContentType("text/html");
pw = res.getWriter();
query = "Select ";
str = req.getParameter("Field_Names"); // GETTING FIELD NAMES
query = query + str + " from Promotion";
chbxeCode = chbxeCode+ req.getParameter("eCode"); // GETTING STATUS OF CHECKBOX
chbxproDate = chbxproDate + req.getParameter("proDate");
chbxproPost = chbxproPost + req.getParameter("proPost");
// NOW QUERY FORMED HERE IN BETWEEN
// ACCORDING TO CHECKBOX
pw.println(query);// this prints query as just to verify if properly constructed , & IT SHOWS XPECTED QUERY
// NOW MANAGEMENT OF DATABASE
try
{
ResultSet rs = stmt.executeQuery(query); // here is a problem
pw.println("Yes i came inside try !");// IT DOESNT PRINT THIS STATEMENT
ResultSetMetaData rsmd = rs.getMetaData();
int numcols = rsmd.getColumnCount();
// TITLE THE TABLE WITH RESULT SET'S COLUMN LABELS
// ..........code
}
catch(SQLException e)
{

}
}

public void destroy()
{
try
{
stmt.close();
con = null;
}
catch(SQLException e)
{
}
}
}
[This message has been edited by Vikram Deshmukh (edited July 10, 2000).]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try giving the emp_name in single quotes . try the query in access and find whether it works. try appending single quotes .

Originally posted by Vikram Deshmukh:
Here is a code to ease the Qn.
all req imports
public class Selection extends HttpServlet
{
Connection con;
Statement stmt;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
// initializing database drivers
String driverName,url,user,password;
Driver driver;
try
{
driverName = "sun.jdbc.odbc.JdbcOdbcDriver";//using JdbcOdbc bridge
driver = (Driver)Class.forName(driverName).newInstance();// registering driver
url = "jdbc dbc:Promo"; // Data Source Name
user = "";
password = "";
con = DriverManager.getConnection(url,user,password);
stmt = con.createStatement();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws IOException, ServletException
{
String chbxeCode = new String();
String chbxproDate = new String();
String chbxproPost = new String();
String query = new String();
String str = null;
boolean flag = false;
String eCode = null;
String ePromoDate = null;
String ePromoPost = null;
Object obj = null;
PrintWriter pw = null;
res.setContentType("text/html");
pw = res.getWriter();
query = "Select ";
str = req.getParameter("Field_Names"); // GETTING FIELD NAMES
query = query + str + " from Promotion";
chbxeCode = chbxeCode+ req.getParameter("eCode"); // GETTING STATUS OF CHECKBOX
chbxproDate = chbxproDate + req.getParameter("proDate");
chbxproPost = chbxproPost + req.getParameter("proPost");
// NOW QUERY FORMED HERE IN BETWEEN
// ACCORDING TO CHECKBOX
pw.println(query);// this prints query as just to verify if properly constructed , & IT SHOWS XPECTED QUERY
// NOW MANAGEMENT OF DATABASE
try
{
ResultSet rs = stmt.executeQuery(query); // here is a problem
pw.println("Yes i came inside try !");// IT DOESNT PRINT THIS STATEMENT
ResultSetMetaData rsmd = rs.getMetaData();
int numcols = rsmd.getColumnCount();
// TITLE THE TABLE WITH RESULT SET'S COLUMN LABELS
// ..........code
}
catch(SQLException e)
{

}
}

public void destroy()
{
try
{
stmt.close();
con = null;
}
catch(SQLException e)
{
}
}
}
[This message has been edited by Vikram Deshmukh (edited July 10, 2000).]


 
Vikram Deshmukh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx it worked . My new query i'm posting after this .
 
We're being followed by intergalactic spies! Quick! Take this tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic