<!-- JSP Program to create table in Oracle 10g, insert values in it and display the same. -->
<html>
<head>
<title>Student Information</title>
<%@page import="java.sql.*,java.util.*"%>
</head>
<body>
<%
try
{
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","tiger");
//step3 create the statemnt object
Statement stmt=con.createStatement();
//stmt.executeUpdate("create table mytable1(NAME varchar2(20),DOB varchar2(15))");
System.out.println("Table created successfully!");
stmt.executeQuery("insert into mytable1 values('Vijay','10-SEP-2000')");
//step4 execute query
ResultSet rs=stmt.executeQuery("select * from mytable1");
while(rs.next())
{
%>
<CENTER>
<table border=5 bgcolor="orange" height=50 width=100 >
<caption><h3><font color="blue" >MyTable</font></h3></caption>
<tr><td><%=rs.getString("NAME")%></td><td><%=rs.getString("DOB")%></td></tr>
</table>
</CENTER>
<%
}
//step5 close the connection object
con.close();
}catch(Exception e){ System.out.println(e);}
%>
</body>
</html>
<html>
<head>
<title>Student Information</title>
<%@page import="java.sql.*,java.util.*"%>
</head>
<body>
<%
try
{
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","tiger");
//step3 create the statemnt object
Statement stmt=con.createStatement();
//stmt.executeUpdate("create table mytable1(NAME varchar2(20),DOB varchar2(15))");
System.out.println("Table created successfully!");
stmt.executeQuery("insert into mytable1 values('Vijay','10-SEP-2000')");
//step4 execute query
ResultSet rs=stmt.executeQuery("select * from mytable1");
while(rs.next())
{
%>
<CENTER>
<table border=5 bgcolor="orange" height=50 width=100 >
<caption><h3><font color="blue" >MyTable</font></h3></caption>
<tr><td><%=rs.getString("NAME")%></td><td><%=rs.getString("DOB")%></td></tr>
</table>
</CENTER>
<%
}
//step5 close the connection object
con.close();
}catch(Exception e){ System.out.println(e);}
%>
</body>
</html>
Thanks for sharing this good blog.This is very important and imformative
ReplyDeleteblog for Java . very interesting and useful for students
Java Online Training