aspose file tools*
The moose likes Servlets and the fly likes Servlet - JDBC interaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet - JDBC interaction " Watch "Servlet - JDBC interaction " New topic
Author

Servlet - JDBC interaction

Vikram Deshmukh
Greenhorn

Joined: Apr 22, 2000
Posts: 29
Dear friends ,
i'm using JDBC connectivity in the HttpServlet . Here is my query for
executeQuery as a parameter ,
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 .
Vikram Deshmukh
Greenhorn

Joined: Apr 22, 2000
Posts: 29
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)
{
}
}
}
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
ur query u've written is
Select Promotion_Date from Promotion where Emp_Code = a4
probably Emp_Code must be a field of text,so a4 should be in single or double quotes,
(run the sql query seperately and confirm its executing)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet - JDBC interaction
 
Similar Threads
General Error in SQL Server 2000
connection
Error while accessing MSAccess in JSP
unable to connect to MS SQL server 2000
How to convert Blob Type back to File