Delete Clob From Oracle in a Servlet : Database « Servlets « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Servlets » DatabaseScreenshots 
Delete Clob From Oracle in a Servlet

/*
Defining the Table: Oracle 9i

The following defines a table based on Oracle 9i:

create table DataFiles (
    id INT PRIMARY KEY,
    fileName VARCHAR(20),
    fileBody CLOB
);

Defining the Table: MySQL

The following defines a table based on MySQL:

create table DataFiles (
    id INT PRIMARY KEY,
    fileName VARCHAR(20),
    fileBody TEXT
);

*/
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DeleteClobFromOracleServlet extends HttpServlet {

  public static Connection getConnection() throws Exception {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:databaseName";
    String username = "userName";
    String password = "password";
    Class.forName(driver);
    Connection conn = DriverManager.getConnection(url, username, password);
    return conn;
  }

  public void doGet(HttpServletRequest request, HttpServletResponse responsethrows IOException,
      ServletException {

    Connection conn = null;
    PreparedStatement pstmt = null;
    String id = "001";
    ServletOutputStream out = response.getOutputStream();
    response.setContentType("text/html");
    out.println("<html><head><title>Delete CLOB Record</title></head>");

    try {
      conn = getConnection();
      pstmt = conn.prepareStatement("delete from DataFiles where id = ?");
      pstmt.setString(1, id);
      pstmt.executeUpdate();
      out.println("<body><h4>deleted CLOB record with id=" + id + "</h4></body></html>");
    catch (Exception e) {
      out.println("<body><h4>Error=" + e.getMessage() "</h4></body></html>");
    finally {
      try {
        pstmt.close();
        conn.close();
      catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }

  public void doPost(HttpServletRequest request, HttpServletResponse responsethrows IOException,
      ServletException {
    doGet(request, response);
  }
}

           
       
Related examples in the same category
1. Servlets Database Query
2. Using JDBC in Servlets
3. Cached Connection Servlet
4. Transaction Connection Servlet
5. Session Login JDBC
6. JDBC and Servlet
7. Database and Servlet: Database MetaData
8. Database and Servlet: Store procedure
9. Database transaction
10. Typical database commands
11. Process a raw SQL query; use ResultSetMetaData to format it
12. See Account
13. Guest Book Servlet
14. Dedicated Connection Servlet
15. Login Servlets
16. OCCI Connection Servlet
17. Get Column Names From ResultSet
18. Display Clob Servlet
19. Delete Blob From Servlet
20. Delete Clob From Servlet
21. Display Blob Servlet
22. Insert Clob to MySql Servlet
23. Update Clob data stored in MySql from a Servlet
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.