J2ee CH - 3 Program - 26 To 39
J2ee CH - 3 Program - 26 To 39
(25)Addition
<html>
<body>
<hr>
<%!int a,b,ans;%>
<%
a=10;
b=20;
ans=a+b;
%>
<%="Sum is"+ans%>
</h1>
</body>
</html>
-----------------------------------------
(26) if_else
<html>
<body>
<h1>Positive Or Nagative
<hr>
<%!int a=8;%>
<%
if(a>0)
{
%>
<%="a is Positive"%>
<%
}
else
{
%>
<%="a is Nagative"%>
<%
}
%>
</h1>
</body>
</html>
---------------------------------------------
(27) Expression tag - welcome message
<html>
<body bgcolor="pink">
<hr>
<hr>
</h1>
</body>
</html>
-----------------------------------------------------
------------------------------------------
(29) employee.jsp
<h1>
<%="emp name"+request.getParameter("enm")%>
<%="salary"+request.getParameter("sal")%>
</h1>
(29) jspforward.jsp
<%="hello"%>
<jsp:forward page="employee.jsp">
<jsp:param name="enm" value="om"/>
<jsp:param name="sal" value="5000"/>
</jsp:forward>
(29) jspinclude.jsp
<%="hello"%>
<jsp:include page="employee.jsp">
<jsp:param name="enm" value="om"/>
<jsp:param name="sal" value="5000"/>
</jsp:include>
--------------------------------------------------
(30) if program
<%! int i=1; %>
<%
if(i>0)
{
out.println("True");
}
%>
-------------------------------------------------
(31) datedemo
<%
for(int i=1; i<=5; i++)
{
%>
<%
out.println("<b>GOOD ByE... " + i + "<b><BR>");
}
%>
(31) second.jsp
(31) LineDraw.jsp
<HR height = 300 width = 200>
----------------------------------------------
(32) Expression.jsp
<%! int a = 1; %>
<%= a %>
<% a++; %>
<br>
------
i++;
%>
-----------------------------------------------------------
(33) for loop
<%! int i; %>
<%
for(i=1;i<=5;i++)
{
%>
<%@ include file="simple.jsp" %>
<%
}
%>
(33) simple.jsp
---------------------------------------------------------
(34) while loop
<%! int i=1; %>
<%
while(i<=5)
{
out.println(i+"<br>");
i++;
}
%>
----------------------------------------------------------
(35) pyramid.jsp
<%! int i,j,k; %>
<%
for(i=1;i<5;i++)
{
for(j=1;j<=i;j++)
{
out.println("*");
}
out.println("<br>");
}
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
out.println("*");
}
out.println("<br>");
}
%>
------------------------------------------------
(36) connectivity program JSP with MS-ACCESS
<html>
<body>
Connection cn;
ResultSet rs;
Statement st;
String q;
%>
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=DriverManager.getConnection("jdbc:odbc:mydsn");
st=cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
out.println("connection done");
rs=st.executeQuery(q);
while(rs.next())
out.println("<tr>");
out.println("<td>"+rs.getInt(1));
out.println("<td>"+rs.getString(2));
out.println("<td>"+rs.getString(3));
}
st.close();
cn.close();
catch(Exception e){System.out.println(e);}
%>
</h1>
</body>
</html>
---------------------------------------------------------------
(37) Connectivity JSP with MYSQL
<h1>Hello Students
<%!
Connection cn;
ResultSet rs;
Statement st;
String q;
%>
<%
try
Class.forName("com.mysql.jdbc.Driver");
cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/hnsmysql","root","");
st=cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
out.println("connection done");
rs=st.executeQuery(q);
while(rs.next())
{
out.println("<tr>");
out.println("<td>"+rs.getInt(1));
out.println("<td>"+rs.getString(2));
st.close();
cn.close();
catch(Exception e) {}
%>
</h1>
</body>
</html>
------------------------------------------
(38) just understanding of all database and its driver (no need to write)
import java.sql.*;
class select_mysql
{
public static void main(String args[])
{
try
{
Connection cn;
Statement st;
ResultSet rs;
Class.forName("com.mysql.jdbc.Driver");
cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/hns","root","");
System.out.println("Connection done");
st=cn.createStatement();
rs = st.executeQuery("select * from student");
while(rs.next())
{
int rno = rs.getInt(1);
String name = rs.getString(2);
String city=rs.getString(3);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
--------------------------------------------------------