<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="java.sql.*;" %> 
<%@ page import="java.io.*;" %>>
<%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Database Page</title>
</head>

<body background="AC.jpg">

<a href="home.jsp"><font color="white"size="3"><b>Back to Home</b></font></a>
<% try
{
String a=request.getParameter("Book_Id"); 
String b=request.getParameter("Book Name");
String c=request.getParameter("Author name");
String d=request.getParameter("Publisher name");
String e=request.getParameter("Department");
String f=request.getParameter("Edition");
String g=request.getParameter("no_of_copy");

Connection con = DriverManager.getConnection("jdbc:odbc:proj","","");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String query ="select * from BookMaster where Book_Id='" + a + "'";
ResultSet rs=stmt.executeQuery(query);
if(rs.next())
{

response.sendRedirect("BookMasterForm.jsp?result=Book_Id already exists");
}
else
{
rs.updateString("Book_Id",a);
rs.updateString("Book Name",b);
rs.updateString("Author name",c);
rs.updateString("Publisher name",d);
rs.updateString("Department",e);
rs.updateString("Edition",f);
rs.updateString("no_of_copy",g);
rs.insertRow();

response.sendRedirect("BookMasterForm.jsp?result=Succesfully inserted");	
}

rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{ e.printStackTrace();
}

%>


</body>
</html>

Dani AI

Generated

The symptom "no exception, no rows inserted" usually comes from one of a few common mistakes rather than a mysterious driver bug. posted an updatable-ResultSet approach from a JSP and correctly suggested moving DB work out of the page. The immediate action plan is: verify the inputs, verify the DB access method, then use a simple INSERT via PreparedStatement (safer and easier to debug).

Quick checklist to run now:

  • Confirm the HTML form input names exactly match the names you read with request.getParameter(...). Print or log each parameter to make sure none are null or empty.
  • Avoid spaces in form field names and column identifiers; rename to bookName or BookName (or quote identifiers properly in SQL).
  • Test the same INSERT in a DB client (mysql shell, phpMyAdmin) to ensure the table accepts the values and you are connected to the expected database.
  • Check server logs for stack traces. If autocommit was altered, ensure you commit or call executeUpdate which returns the affected row count.

Recommended replacement pattern (move this into a servlet/DAO, not JSP):

String sql = "INSERT INTO BookMaster (Book_Id, BookName, AuthorName, PublisherName, Department, Edition, no_of_copy) VALUES (?, ?, ?, ?, ?, ?, ?)";
try (Connection conn = DriverManager.getConnection("jdbc:mysql://host:3306/yourdb", "user", "pass");
     PreparedStatement ps = conn.prepareStatement(sql)) {

    ps.setString(1, bookId);
    ps.setString(2, bookName);
    // ... set other params ...
    int rows = ps.executeUpdate();
    if (rows == 1) {
        // success
    } else {
        // handle unexpected result
    }
}

Notes and cautions:

  • Use the official MySQL JDBC driver (Connector/J) and a proper JDBC URL instead of legacy ODBC bridges.
  • If you must use an updatable ResultSet, call rs.moveToInsertRow() before updateXXX(...) and rs.insertRow() afterwards — but PreparedStatement is simpler and more portable.
  • Keep DB code out of JSP for maintainability, testing, and clearer error handling (as suggested).

Yak what and ugly thing to do database connectivity from page instead of servlet. Check this tutorial how to do it properly or even better start reading Head First Servlet and JSP

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.