- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Download Jar File :
Link for MySQL Connector: https://drive.google.com/open?id=16tEVI9e2aXlMTiiz6DxeOiUaeh-7lIQ4
index.jsp :
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="post">
ID:
<input type="text" name="txteid">
<br>
NAME:
<input type="text" name="txtename">
<br>
SALARY:
<input type="text" name="txtesal">
<br>
<input type="submit" name="bt" value="ADD">
<br>
<input type="submit" name="bt" value="Show All Data">
</form>
<%
if("ADD".equals(request.getParameter("bt")))
{
String eid=request.getParameter("txteid");
String en=request.getParameter("txtename");
int es=Integer.parseInt(request.getParameter("txtesal"));
Connection con;
PreparedStatement ps;
Class.forName("com.ibm.db2.jcc.DB2Driver"); // DB2 Connection Driver
con=DriverManager.getConnection("jdbc:db2://dashdb-txn-sbox-yp-lon02-02.services.eu-gb.bluemix.net:50000/BLUDB","lbr58476","lwkvq5-f0lsg587w");
// getConnection(server location,username,password) used for make connect between JSP and MySQL
// 3306 is the default port number for connecting JSP to MySQL Database.
ps=con.prepareStatement("INSERT INTO emp VALUES(?,?,?)");
ps.setString(1, eid);
ps.setString(2, en);
ps.setInt(3, es);
ps.executeUpdate();
// executeUpdate() is used for executing the SQL query into the Database.
out.println("Record Added");
}
%>
</body>
</html>
Showdata.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
Connection con;
PreparedStatement ps;
ResultSet rs;
Class.forName("com.ibm.db2.jcc.DB2Driver"); // DB2 Connection Driver
con=DriverManager.getConnection("jdbc:db2://dashdb-txn-sbox-yp-lon02-02.services.eu-gb.bluemix.net:50000/BLUDB","lbr58476","lwkvq5-f0lsg587w");
// getConnection(server location,username,password) used for make connect between JSP and MySQL
// 3306 is the default port number for connecting JSP to MySQL Database.
ps=con.prepareStatement("SELECT * FROM emp");
rs=ps.executeQuery();
%>
<table width="400px" border="1px">
<tr>
<th>ID</th>
<th>NAME</th>
<th>SALARY</th>
</tr>
<%
while(rs.next()) // execute loop until end of record
{
%>
<tr>
<td>
<%
out.println(rs.getString(1));
%>
</td>
<td>
<%
out.println(rs.getString(2));
%>
</td>
<td>
<%
out.println(rs.getInt(3));
%>
</td>
</tr>
<%
}
%>
</table>
</body>
</html>
Comments
Post a Comment