Click here to Skip to main content
15,889,739 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Now i am working in jsp eclipse. Now i created connection to mysql database. but i can't insert value in database. please give the solution. My code is as below:




XML
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@page import="com.Sterling.corejava.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Employee Information</title>
<body>
<%
// get parameters from the request
String LibraryId = request.getParameter("LibraryId");
String LibraryName= request.getParameter("LibraryName");
String LibraryPhno= request.getParameter("LibraryPhno");
String  LibraryEmail= request.getParameter("LibraryEmail");
String LibraryAddr= request.getParameter("LibraryAddr");
String FacultyId= request.getParameter("FacultyId");
String Password= request.getParameter("Password");
// declare a connection by using Connection interface
Connection con = null;
Statement stat=null;
try {
    String connectionURL = "jdbc:mysql://localhost:3306/libraydatabase";
    Class.forName("com.mysql.jdbc.Driver").newInstance ();
     con = DriverManager.getConnection(connectionURL, "root", "root123");
    out.println("Connection Opened to database.");
     stat=con.createStatement();

    //String InsertQuery="Select * from tbllibrarian";
    //System.out.println("shgfsxv");
    String InsertQuery="insert into tbllibrarian(LibraryId,LibraryName,LibraryPhno,LibraryEmail,LibraryAddr,Password) values(11,'weryty',1234,'asdfr@gmail.com','Baramati','****');";
   //System.out.println("megha");
    try
    {
        stat.executeUpdate(InsertQuery);
        out.println("Record Inserted to database successfully.");
    }
    catch(SQLException e)
    {
        out.println("Unable to Insert Record to database.");
    }



}
catch(SQLException ex)
{
    out.println("Unable to connect to database.");
}
%>
</body>
</html>
Posted
Updated 2-Jun-18 18:30pm

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900