vb.net print barcode Figure 8-25. Viewing an inserted CLOB record using a servlet in Font

Maker PDF-417 2d barcode in Font Figure 8-25. Viewing an inserted CLOB record using a servlet

Figure 8-25. Viewing an inserted CLOB record using a servlet
PDF 417 Maker In None
Using Barcode printer for Font Control to generate, create PDF 417 image in Font applications.
www.OnBarcode.com
UPC-A Supplement 2 Generator In None
Using Barcode generation for Font Control to generate, create UPC A image in Font applications.
www.OnBarcode.com
Solution: InsertClobToMySqlServlet
Code 3 Of 9 Printer In None
Using Barcode encoder for Font Control to generate, create ANSI/AIM Code 39 image in Font applications.
www.OnBarcode.com
Generating Code 128 Code Set B In None
Using Barcode drawer for Font Control to generate, create Code 128B image in Font applications.
www.OnBarcode.com
The MySQL solution is identical to the Oracle solution with the exception of the getConnection() method, which returns a MySQL Connection object. You can download the complete MySQL solution from the book s Web site.
Generating EAN13 In None
Using Barcode creation for Font Control to generate, create GS1 - 13 image in Font applications.
www.OnBarcode.com
ECC200 Printer In None
Using Barcode printer for Font Control to generate, create Data Matrix 2d barcode image in Font applications.
www.OnBarcode.com
CHAPTER 8 READING AND WRITING CLOBS
Quick Response Code Drawer In None
Using Barcode printer for Font Control to generate, create Quick Response Code image in Font applications.
www.OnBarcode.com
Print UPC-E Supplement 5 In None
Using Barcode creator for Font Control to generate, create GS1 - 12 image in Font applications.
www.OnBarcode.com
The following is getConnection() for the MySQL database: public static Connection getConnection() throws Exception { String driver = "org.gjt.mm.mysql.Driver"; String url = "jdbc:mysql://localhost/octopus"; String username = "root"; String password = "root"; Class.forName(driver); // load MySQL driver return DriverManager.getConnection(url, username, password); }
Decode PDF 417 In C#
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
PDF 417 Decoder In VS .NET
Using Barcode scanner for .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
8-14. How Do You Update an Existing CLOB of an Oracle Database Using a Servlet
Encode ECC200 In Objective-C
Using Barcode encoder for iPhone Control to generate, create Data Matrix image in iPhone applications.
www.OnBarcode.com
Painting Barcode In VS .NET
Using Barcode creation for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
The SQL UPDATE statement modifies the existing column s data in a table. The simplified syntax is as follows (which updates a single column): UPDATE table_name SET column_name_1 = new_value_1, cloumn_name_2 = new_value_2, ... WHERE column_name_x = some_value_1 and column_name_y = some_value_2 and ... You can update any number of columns using the SQL UPDATE statement. For details, please refer to the following Web site: http://www.w3schools.com/sql/sql_update.asp. To update a CLOB in an Oracle database using a servlet, you will represent the new value of a CLOB as a URL (the URL will be pointing to a CLOB data, such as a text file). The reason for this is that servlets cannot access the local file system (a client s/browser s local machine). You can also pass the new CLOB value to the database as a String object. Therefore, you will represent the new value of a CLOB as a URL. The following sections use the DataFiles table defined in the earlier sections.
Barcode Recognizer In .NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Printing ECC200 In None
Using Barcode generation for Office Word Control to generate, create Data Matrix image in Office Word applications.
www.OnBarcode.com
Setting Up the Oracle Database
UPC A Generator In Visual Studio .NET
Using Barcode creation for ASP.NET Control to generate, create UPCA image in ASP.NET applications.
www.OnBarcode.com
Making UPC - 13 In Visual Studio .NET
Using Barcode creation for .NET Control to generate, create UPC - 13 image in .NET applications.
www.OnBarcode.com
Oracle 10 has simplified CLOBs in JDBC. There is no need to use Oracle s proprietary SQL functions, such as empty_clob. Inserting/updating CLOBs is simple; in fact, CLOBs are just long String objects. This shows how to set up the database: $ sqlplus scott/tiger SQL*Plus: Release 10.1.0.2.0 - Production on Sat Feb 19 22:38:38 2005 Copyright (c) 1982, 2004, Oracle. All rights reserved. SQL> desc datafiles; Name Null ------------------------------- -------ID NOT NULL FILENAME FILEBODY
Printing EAN 128 In .NET
Using Barcode printer for Reporting Service Control to generate, create UCC - 12 image in Reporting Service applications.
www.OnBarcode.com
Drawing Code-39 In Java
Using Barcode encoder for BIRT reports Control to generate, create Code 39 image in Eclipse BIRT applications.
www.OnBarcode.com
Type ---------NUMBER(38) VARCHAR2(20) CLOB
Read PDF417 In VB.NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Print QR Code In None
Using Barcode creation for Online Control to generate, create QR-Code image in Online applications.
www.OnBarcode.com
SQL> select id, filename, filebody from datafiles where id=1000; ID ----1000 FILENAME -------file1 FILEBODY ---------------------------this is file1. hello world.
CHAPTER 8 READING AND WRITING CLOBS
SQL> update datafiles 2 set filebody='this is a long ... string. aha.' 3 where id=1000; 1 row updated. SQL> commit; Commit complete. SQL> select id, filename, filebody from datafiles where id=1000; ID FILENAME FILEBODY ----- -------------------------------------1000 file1 this is a long ... string. aha.
Creating the Oracle Servlet Interface
The servlet interface is as follows: http://localhost:8000/octopus/servlet/UpdateOracleClobServlet id=<id>&file=<file-as-URL> Therefore, UpdateOracleClobServlet has two parameters: id (the ID of file, which uniquely identifies record) file (the URL of file representing the CLOB; the servlet will open the URL, construct a CLOB, and update it into the CLOB column of the DataFiles table) Let s update an existing record with the following data in the DataFiles table: id (1000) file (the URL of file: http://www.geocities.com/mparsian/data/file500.txt) Figure 8-26 shows the content of the URL (http://www.geocities.com/mparsian/data/ file500.txt).
Figure 8-26. Displaying a file using a servlet
Therefore, the servlet call is as follows (but all in one line): http://localhost:8000/octopus/servlet/UpdateOracleClobServlet id=1000&file=http://www.geocities.com/mparsian/data/file500.txt
Updating an Existing CLOB Record
Figure 8-27 shows the result of updating an existing CLOB record.
CHAPTER 8 READING AND WRITING CLOBS
Figure 8-27. Updating a CLOB using a servlet
Database Content After Insertion
The following shows the database after the insertion: SQL> select id, filename, filebody from datafiles where id=1000; ID ---1000 FILENAME -------file1 FILEBODY ---------------------------------This is the first line of file500. This is the 2nd of file500. This is the end
Using DisplayOracleClobServlet, you can view the CLOB in a Web browser, as shown in Figure 8-28.
Figure 8-28. Viewing an updated CLOB using a servlet
The Solution: UpdateOracleClobServlet
The following shows the UpdateOracleClobServlet solution: import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import jcb.db.DatabaseUtil; import jcb.util.IOUtil; public class UpdateOracleClobServlet extends HttpServlet { static final String UPDATE_CLOB = "update datafiles set filebody= where id= "; public static Connection getConnection() throws Exception {... } public void doGet(...) {... } public void doPost(...) {...}
CHAPTER 8 READING AND WRITING CLOBS
public void updateCLOB(...) {....} public static String getClobsContentAsString(...) {...} private static String trimParameter(...) {...} }
getConnection()
The following shows getConnection(): public static Connection getConnection() throws Exception { String driver = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oracle:thin:@localhost:1521:caspian"; String username = "scott"; String password = "tiger"; Class.forName(driver); // load Oracle driver return DriverManager.getConnection(url, username, password); }
doGet()
The following shows doGet(): public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String fileContent = null; Connection conn = null; String id = trimParameter(request.getParameter("id")); String fileAsURL = trimParameter(request.getParameter("file")); ServletOutputStream out = response.getOutputStream(); response.setContentType("text/html"); out.println("<html><head><title>UpdateOracleClobServlet</title></head>"); try { conn = getConnection(); fileContent = getClobsContentAsString(fileAsURL); updateCLOB(conn, id, fileContent); out.println("<body><h4>OK: updated an existing "+ record with id="+id+"</h4></body></html>"); } catch(Exception e) { e.printStackTrace(); out.println("<body><h4>Error: "+e.getMessage()+"</h4></body></html>"); } }
updateCLOB()
The following shows updateCLOB(): public void updateCLOB(Connection conn, String id, String fileContent) throws Exception { PreparedStatement pstmt = null; try { pstmt = conn.prepareStatement(UPDATE_CLOB); pstmt.setString(1, fileContent); pstmt.setString(2, id);
Copyright © OnBarcode.com . All rights reserved.