WEB DATABASE USING DATSOURCE IN JSP
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.Context"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
int sno = 0;
String name = request.getParameter("uname");
String address = request.getParameter("uaddress");
Context ctx = new InitialContext(); //CONTEXT CREATION
DataSource ds = (DataSource)ctx.lookup("jdbc/myData"); //JNDI name
Connection con = ds.getConnection();
Statement st = con.createStatement();
st.executeUpdate("insert into t1 values('"+sno+"','"+name+"', '"+address+"')");
out.print("INSERTED SUCCESSFULLY");
%>
</body>
</html>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.Context"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
int sno = 0;
String name = request.getParameter("uname");
String address = request.getParameter("uaddress");
Context ctx = new InitialContext(); //CONTEXT CREATION
DataSource ds = (DataSource)ctx.lookup("jdbc/myData"); //JNDI name
Connection con = ds.getConnection();
Statement st = con.createStatement();
st.executeUpdate("insert into t1 values('"+sno+"','"+name+"', '"+address+"')");
out.print("INSERTED SUCCESSFULLY");
%>
</body>
</html>
No comments:
Post a Comment