Seventh Lesson on JSP
Now We are going to make a telephone Directory with JDBC. There is a table in my database(i used Oracle) named "phone". The query is used to create is
create table phone(
name varchar2(20),
phone varchar2(15));
And after inserting values the table is like
Now i have to create the front end page like
The required Code for this page is like ::
<%--
Document : jdbc1
Created on : 2 Nov, 2012, 5:41:02 PM
Author : NESTED CODE
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body><h1>
<center>Enter Information<br>
<form action="jdbcjsp1.jsp">
Enter the name :: <input type="text" name="n" >
<br><br><input type="submit" value="Submit">
</form>
</center></h1>
</body>
</html>
Document : jdbc1
Created on : 2 Nov, 2012, 5:41:02 PM
Author : NESTED CODE
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body><h1>
<center>Enter Information<br>
<form action="jdbcjsp1.jsp">
Enter the name :: <input type="text" name="n" >
<br><br><input type="submit" value="Submit">
</form>
</center></h1>
</body>
</html>
Now we have to make the "jdbcjsp1.jsp" page.
Here is the required code ::
<%--
Document : jdbcjsp1
Created on : 2 Nov, 2012, 5:45:34 PM
Author : NESTEDCODE TEAM
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body>
<center>
<h1>Telephone Directory</h1>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.sql.DriverManager.*" %>
<%
String m=null, mn=null;
String s=request.getParameter("n");
PreparedStatement ps=null;
Connection con= null;
ResultSet rs= null;
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","root");
Statement st=con.createStatement();
rs=st.executeQuery("select * from phone where name='"+ s+"' ");
while(rs.next())
{
m=rs.getString(1);
mn=rs.getString(2);
}
out.println("<br>");
out.println("<h1>");
out.println("<pre>");
out.println("name =" +m);
out.println("<br>");
out.println("ph no. =" +mn);
out.println("</pre>");
out.println("</h1>");
%>
</center>
</body>
</html>
Document : jdbcjsp1
Created on : 2 Nov, 2012, 5:45:34 PM
Author : NESTEDCODE TEAM
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body>
<center>
<h1>Telephone Directory</h1>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.sql.DriverManager.*" %>
<%
String m=null, mn=null;
String s=request.getParameter("n");
PreparedStatement ps=null;
Connection con= null;
ResultSet rs= null;
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","root");
Statement st=con.createStatement();
rs=st.executeQuery("select * from phone where name='"+ s+"' ");
while(rs.next())
{
m=rs.getString(1);
mn=rs.getString(2);
}
out.println("<br>");
out.println("<h1>");
out.println("<pre>");
out.println("name =" +m);
out.println("<br>");
out.println("ph no. =" +mn);
out.println("</pre>");
out.println("</h1>");
%>
</center>
</body>
</html>
The Output ::
NOTE:: "jdbc:oracle:thin:@localhost:1521:xe","system","root", so here my oracle login id and password is like "system","root". I used Oracle 10g.
Previous Lesson Next Lesson
Previous Lesson Next Lesson
Wow, Excellent post. This article is really very interesting and effective. I think its must be helpful for us. Thanks for sharing your informative.
ReplyDeletesocial exchange sites
social bookmarking sites list
directory submission site list
article submission sites
blog commenting sites
forum posting sites
press release sites list
seo tutorial
free seo tools
freelancing
Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.. free 0800 numbers
ReplyDeleteThanks for your valuable comments! Keep visiting our site - about to publish some more tutorials on cutting edge technologies!! Happy learning!!
Deleteyup..great article!! u have all the qualities to start an youtube channel!! i will be the first subscriber..
ReplyDeleteThanks for your comments!
DeleteWe are about to publish our YouTube channel... We will let you know the update! Stay tuned!! Happy learning!!
The impression a voyance-par-telephone-amour.com caller forms when they first contact your Professional Office can have a direct influence on your success. The busy secretary or receptionist can quickly adopt attitudes and habits on the telephone that are, to say the least, discouraging to your Clients. Here we offer some core telephone skills tips and techniques to refresh your Office Team.
ReplyDelete