import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; public class GetInfo extends HttpServlet { public void doGet ( HttpServletRequest req, // This provides information sent by the browser HttpServletResponse res // This is used to send information back to the browser ) throws ServletException, // General exception that should be thrown if there // is a unrecoverable error in the Servlet IOException { // Set the MIME type for the information being sent to the browser. // In this case, we are going to send back HTML res.setContentType( "text/html" ); // Get a reference to the output stream. // Anything written to this stream is sent directly to the browser // (The browser sees this as its input). ServletOutputStream out = res.getOutputStream(); // The following println statements create an HTML page. // Notice that the , , and // tags are all properly formed HTML syntax. /* out.println( "" ); out.println( "Hello World" ); out.println( "" ); out.println( "

Hello World

" ); out.println( "

Congratulations, your first servlet is working!

" ); out.println( "" ); out.println( "" ); out.close();*/ boolean error=false; String url; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); url="jdbc:odbc:"+"shop"; /*System.out.print("user name:"); String username= new BufferedReader (new InputStreamReader(System.in)).readLine(); /*System.out.print("password:"); String password= new BufferedReader (new InputStreamReader(System.in)).readLine();*/ Connection con=DriverManager.getConnection(url,"shop","shop"); String query= "select code,name,price from articles"; Statement stmt=con.createStatement(); ResultSet rs; int code,price; String name; try { // executing the query for retrieving the data rs = stmt.executeQuery(query); // got to the first record String shop="shop.xml"; FileWriter fw=null; PrintWriter pw=null; try{ fw=new FileWriter(shop); pw=new PrintWriter(fw); }catch(Exception e){ } out.println(""); // out.println(""); out.println(""); // root element out.println(""); while(rs.next()) { code=rs.getInt(1); name=rs.getString(2); price=rs.getInt(3); out.println(""); out.println("" + code + ""); out.println("" + name + "" ); out.println(""+price+""); out.println(""); } out.println(""); out.close(); } catch(SQLException e) { System.out.println(e.getMessage()); System.out.println("error:education"); } } catch(Exception e) { error=true; System.out.println(e); } if(error) { System.out.println("error in connecting to the databse"); } } }