updation problem

They have: 1 posts

Joined: Nov 2004

I have an jsp page name students.jsp like that:

the updation function is not working.when i click on update it shows error "General Error".

The Save function is working, but the updation function is not working.

plz help me in my coding.

<?php
@ page import="javax.servlet.*"
?>

<?php
@ page import="javax.servlet.http.*"
?>

<?php
@ page language="java" import="java.sql.*"
?>

<?php
 
try {
 
Class.
forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:pf","scott","ttlscott");
System.out.println("got connection");
   
?>

<?php
String action
= request.getParameter("action");
if (
action != null && action.equals("save")) {
conn.setAutoCommit(false);
                       
// Create the prepared statement and use it to
// INSERT the employee attrs INTO the GL_MAST table.
PreparedStatement pstmt = conn.prepareStatement(
(
"INSERT INTO gl_mast VALUES (?, ?,  ?, ?, ?, ?)"));
pstmt.setInt(1,Integer.parseInt(request.getParameter("gl_code")));
pstmt.setString(2, request.getParameter("gl_descr"));
pstmt.setInt(3,Integer.parseInt(request.getParameter("db_amt")));
pstmt.setInt(4,Integer.parseInt(request.getParameter("cr_amt")));
pstmt.setString(5, request.getParameter("gl_type"));
pstmt.setInt(6,Integer.parseInt(request.getParameter("gl_pct")));
pstmt.executeUpdate();
conn.commit();
conn.setAutoCommit(true);
}

// Check if an update is requested
if (action != null && action.equals("update")) {
conn.setAutoCommit(false);
                       
// Create the prepared statement and use it to
// UPDATE the employee attributes in the GL_MAST table.

PreparedStatement pstatement = conn.prepareStatement(
"UPDATE gl_mast SET gl_descr = ?, db_amt = ?,  " +
"cr_amt = ?, gl_type = ? , gl_pct = ?  WHERE gl_code=?");

pstatement.setString(1, request.getParameter("gl_descr"));
pstatement.setInt(2,Integer.parseInt(request.getParameter("db_amt")));
pstatement.setInt(3,Integer.parseInt(request.getParameter("cr_amt")));
pstatement.setString(4, request.getParameter("gl_type"));
pstatement.setInt(5,Integer.parseInt(request.getParameter("gl_pct")));

int rowCount = pstatement.executeUpdate();
conn.setAutoCommit(false);
conn.setAutoCommit(true);
}
?>

<?php
// Create the statement
Statement statement = conn.createStatement();
   
// Use the statement to SELECT the student attributes
// FROM the Student table.
ResultSet rs = statement.executeQuery
 
("SELECT * FROM gl_mast ");
?>

Code
Description
Dr. Amt
Cr. Amt
Type
Pct

<?php
 
// Iterate over the ResultSet
 
while ( rs.next() ) {
?>

<?php
 
}
?>

<?php
// Close the ResultSet
rs.close();
   
// Close the Statement
statement.close();
   
// Close the Connection
conn.close();
} catch (
SQLException sqle) {
 
out.println(sqle.getMessage());
} catch (
Exception e) {
 
out.println(e.getMessage());
}
?>

plz help me, its urgent

thanx