|
Hi all. I am using DB2 as back end. and i able to insert the query manually. but through jsp i am getting an exception. IN DB all fields are type VARCHAR.
i am new to DB2 and JSP. Plz help
<b>feed.jsp</b>
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="/forum/check_feedback.html" method="post">
<table width="475" border="1">
<tr>
<td width="219">NAME:</td>
<td width="240"><input type="text" name="name1"></td>
</tr>
<tr>
<td>AGE:</td>
<td><input type="text" name="age1"></td>
</tr>
<tr>
<td>RNO:</td>
<td><input type="text" name="rno1"></td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="Submit" value="Submit">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
check_feedback.jsp
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<link rel="stylesheet"
href="${pageContext.request.contextPath}/theme/Master.css"
type="text/css">
<title>check_feedback</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
<% String temp1=(String) request.getParameter("name1");
String temp2=(String) request.getParameter("age1");
String temp3=(String) request.getParameter("rno1");
try {
// create data source
com.ibm.db2.jcc.DB2SimpleDataSource ds =
new com.ibm.db2.jcc.DB2SimpleDataSource();
// set connection properties
ds.setServerName("localhost");
ds.setPortNumber(50000);
ds.setDatabaseName("example1");
ds.setDriverType(4);
// get connection
java.sql.Connection con = ds.getConnection("gururaj", "sdmcet");
java.sql.Statement stmt = con.createStatement();
java.sql.ResultSet rs = null;
%><table><tr><td>
<%out.println(temp1+"\n");%>
</td>
</tr>
<tr>
<td>
<%out.println(temp2+"\n");%>
</td>
</tr>
<tr>
<td>
<%out.println(temp3+"\n");%>
</td>
</tr>
</table>
<%
rs.refreshRow();
rs.moveToCurrentRow();
// rs.moveToInsertRow();
//String query="INSERT INTO gururaj.SAMPLE ('NAME',AGE,RNO) VALUES ("+temp1+","+temp2+","+temp3+")";
//String query="INSERT INTO gururaj.SAMPLE VALUES('temp1','temp2','temp3')";
String query="INSERT INTO gururaj.SAMPLE VALUES ('"+temp1+"','"+temp2+"','"+temp3+"')";
stmt.executeUpdate(query);
//stmt.executeQuery(query);
%>
<jsp:forward page="/forum/success.html"></jsp:forward>
<%
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
out.println("Error "+e.getMessage());
%>
<h1>error</h1>
<%
}
%>
</body>
</html>
input
t
t
t
in all three textboxes
output
t
t
t
Error null
error
|
|
|
|
|
|
|
|