JSP - Inserting into a database
From: PaulD (paulmduff_at_gmail.com)
Date: 03/28/05
- Next message: boki: "J2ME, Canvas, CommandListener."
- Previous message: boki: "Re: J2ME, Canvas,"
- Next in thread: ???: "Re: JSP - Inserting into a database"
- Reply: ???: "Re: JSP - Inserting into a database"
- Reply: kaeli: "Re: JSP - Inserting into a database"
- Reply: Oscar kind: "Re: JSP - Inserting into a database"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 27 Mar 2005 17:11:59 -0800
Hi there,
I'm having problems inserting data into an Access database. Firstly,
I'll mention that I can insert into the database using the following
Prepared statement in my .jsp page:
sql = "INSERT INTO Classifieds(Title, Name, Description, Phone, Email,
Category) VALUES('test','test','test','test','test','test');";
...however, when I change the values to be inserted into variables
which have values assigned to them from a form, I get an SQLException.
Any ideas on what is going wrong would be greatly appreciated!
Thanks,
PaulD
String name = request.getParameter("name");
String phone = request.getParameter("phone");
String email = request.getParameter("email");
String categorytype = request.getParameter("categorytype");
String title = request.getParameter("title");
String description = request.getParameter("description");
String sql = null;
String url ="jdbc:odbc:buysell";
String uid = null;
String pwd = null;
PreparedStatement statement = null;
Connection conn = null;
sql = "INSERT INTO Classifieds(Title, Name, Description,
Phone, Email, Category)
VALUES(title,name,description,phone,email,category);";
try {
conn = DriverManager.getConnection(url,uid,pwd);
statement = conn.prepareStatement(sql);
// statement.setString(1, request.getParameter("title"));
// statement.setString(2, request.getParameter("name"));
// statement.setString(3,
request.getParameter("description"));
// statement.setString(4, request.getParameter("phone"));
// statement.setString(5, request.getParameter("email"));
// statement.setString(6,
request.getParameter("categorytype"));
statement.executeUpdate();
}
- Next message: boki: "J2ME, Canvas, CommandListener."
- Previous message: boki: "Re: J2ME, Canvas,"
- Next in thread: ???: "Re: JSP - Inserting into a database"
- Reply: ???: "Re: JSP - Inserting into a database"
- Reply: kaeli: "Re: JSP - Inserting into a database"
- Reply: Oscar kind: "Re: JSP - Inserting into a database"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|