-
insertion of values through jsp into database
i want a query which i have to be used in jsp page, that the values of html page, which display in jsp page get stored in oracle database.my coonnection is working, but the value is not stored in database.
the values is get from the html page, by using request.getParameter("code") method.
i have used the following query, but it is not working:
<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page language="java" import="java.sql.*" %>
<html>
<head>
<title></title>
<body>
<%
try {
//Load the jdbc driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Create a connection object
Connection con=DriverManager.getConnection("jdbc dbc f","scott","ttlscott");
System.out.println("got connection");
// Create a statement object and call its executeUpdate method to insert a record
Statement s=con.createStatement();
String sql = "insert into gl_mast values(\"" + request.getParameter("code") + "\",\"" + request.getParameter("Description") + "\",\"" + request.getParameter("DrAmount") + "\",\"" + request.getParameter("CrAmount") + "\",\"" + request.getParameter("type") + "\",\"" + request.getParameter("pct") + "\"")";
s.executeUpdate(sql);
Step 4. Use the same Statement object to obtain a ResultSet object
";
ResultSet rs = s.executeQuery(sql);
rs.close();
s.close();
con.close();
}
catch (ClassNotFoundException e1) {
// JDBC driver class not found, print error message to the console
System.out.println(e1.toString());
}
catch (SQLException e2) {
// Exception when executing java.sql related commands, print error message to the console
System.out.println(e2.toString());
}
catch (Exception e3) {
// other unexpected exception, print error message to the console
System.out.println(e3.toString());
}
%>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks