<%@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>

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.