Query Result
This is what I want my user final page to look like.
CID is 222
Container_type is DVD
Container_size is 4gb
Container_desc is Western Digital External Hard Drive. S/N: 86973648396
Project_ID is 118
I have written code to get just one category from database and display on page.
What code can write to access all categories and display the above on one page.
Thank you for your help
this is what my code look like
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<%@ page import="oracle.sql.*" %>
<%@ page import="oracle.jdbc.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String CID;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Media Tracker Print Label</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="description" content="login verification">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body bgcolor="#FFFFCC">
<table width="650" border="1" cellpadding="0" cellspacing="0" bordercolor="#582304">
<tr>
<td><div align="center"><img src="C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MediaTracker\images\header.jpg" align="absbottom" /> </div>
</td>
</tr>
<tr height="380">
<td valign="top">
<%
CID = request.getParameter("CID");
if(CID.equals("") || CID.equals(null)){
out.println("You must enter a Container ID <br><br>click <a href=PrintLabel.jsp>here</a> to try again");
}
else{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@208.42.140.224:1521:XE","ics499","capstone");
System.out.println("loaded class");
String query = "Select container_type from media_infor where cid='"+CID+"' ";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
if( rs.next() ){
out.println ( "The container_type for "+CID + " is ");
String container_type = rs.getString("container_type");
%>
<%= container_type %>
<%
out.println ("<br>Please Click <a href=menu.jsp>MAIN MENU</a> to return to the main menu");
}
else{
out.println("The Container ID you have entered does not exist, try again");
%>
<a href="ViewPrint.jsp">Back</a>
<% }
System.out.println("query executed");
try{
con.close();
}
catch(Exception e){
out.println("conn close exception"+e) ;
}
}
catch(Exception e){
out.println("sql exception loading the class"+e);
}
}
%>
</td>
</tr>
<tr>
<td bgcolor="#582304">
<div align="center"><img src="C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MediaTracker\images\footer.jpg" align="center"></div></td>
</tr>
</table>
</body>
</html>
# 1
[nobr]sorry for the mess that I wrote in last posting, I'll preview before posting.
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<%@ page import="oracle.sql.*" %>
<%@ page import="oracle.jdbc.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String CID;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Media Tracker Print Label</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="description" content="login verification">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body bgcolor="#FFFFCC">
<table width="650" border="1" cellpadding="0" cellspacing="0" bordercolor="#582304">
<tr>
<td><div align="center"><img src="C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MediaTracker\images\header.jpg" align="absbottom" /> </div>
</td>
</tr>
<tr height="380">
<td valign="top"><br>
<%
CID = request.getParameter("CID");
if(CID.equals("") || CID.equals(null)){
out.println("You must enter a Container ID <br><br>click <a href=PrintLabel.jsp>here</a> to try again");
}
else{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@208.42.140.224:1521:XE","ics499","capstone");
System.out.println("loaded class");
String query = "Select container_type from media_infor where cid='"+CID+"' ";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
if( rs.next() ){
out.println ( "The container_type for "+CID + " is ");
String container_type = rs.getString("container_type");
%>
<%= container_type %>
<%
out.println ("<br>Please Click <a href=menu.jsp>MAIN MENU</a> to return to the main menu");
}
else{
out.println("The Container ID you have entered does not exist, try again");
%>
<br><br><a href="ViewPrint.jsp">Back</a>
<% }
System.out.println("query executed");
try{
con.close();
}
catch(Exception e){
out.println("conn close exception"+e) ;
}
}
catch(Exception e){
out.println("sql exception loading the class"+e);
}
}
%>
</td>
</tr>
<tr>
<td bgcolor="#582304">
<div align="center"><img src="C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MediaTracker\images\footer.jpg" align="center"></div></td>
</tr>
</table>
</body>
</html>
[/nobr]
# 3
hi,
better to display your values in table format, it will show a neat output,
same thing for all categories, what doubt in that,
String query = "Select container_type from media_infor";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while ( rs.next() ) {
out.println ( "The container_type for "+CID + " is ");
String container_type = rs.getString("container_type");
%>
<%= container_type %>
<%
}
out.println ("<br>Please Click <a href=menu.jsp>MAIN MENU</a> to return to the main menu");
%>