<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%
// Identify a carriage return character for each output line
int
iLf = 10;
char
cLf = (char)iLf;
// Create a new empty binary file, which will content XML output
File
outputFile = new File(<YourFileName>);
outputFile.createNewFile();
FileWriter
outfile = new FileWriter(outputFile);
// the header for XML file
outfile.write("<?xml
version='1.0' encoding='ISO-8859-1'?>"+cLf);
try
{
?????? // The HTTP request's
parameters to get a database connection
?????? String servernm =
request.getParameter("servernm");
?????? String database =
request.getParameter("database");
?????? String username =
request.getParameter("username");
?????? String password =
request.getParameter("password");
?????? // We access the
database directly from the JSP with the Oracle JDBC driver
?????? DriverManager.registerDriver (new
oracle.jdbc.driver.OracleDriver());
?????? // Define connection
string and make a connection to database
?????? Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@"+servernm+":1521:"+
????????????????????????????????????????????????????
database, username, password);
?????? Statement stat = conn.createStatement();
?????? // Create a recordset
?????? ResultSet rset = stat.executeQuery("Select
* From Cars");
?
?????? // Expecting at least
one record
?????? if( !rset.next() ) {
????????????? throw new
IllegalArgumentException("No data found for the Cars table");
?????? }
?????? outfile.write("<Table>"+cLf);
?????? // Parse our recordset
?????? while(rset.next()) {
????????????? outfile.write("<Cars>"+cLf);
????????????? outfile.write("<Year>"
+ rset.getString("Year") +"</Year>"+cLf);
????????????? outfile.write("<Corporation>"
+ rset.getString("Corporation")
+"</Corporation>"+cLf);
????????????? outfile.write("<CarName>"
+ rset.getString("CarName") +"</CarName>"+cLf);
????????????? outfile.write("</Cars>"+cLf);
?????? }
?????? outfile.write("</Table>"+cLf);
?????? // Everything must be
closed
?????? rset.close();
?????? stat.close();
?????? conn.close();
?????? outfile.close();
}
catch(
Exception er ) {
%>
?????? <exception><%=
er.getMessage()%></exception>
<%
?????? outfile.close();
}