Source Code Cross Referenced for DbmsOutput.java in  » Database-Client » SQL-Workbench » workbench » db » oracle » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
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 Source Code / Java Documentation » Database Client » SQL Workbench » workbench.db.oracle 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DbmsOutput.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.db.oracle;
013:
014:        import java.sql.CallableStatement;
015:        import java.sql.Connection;
016:        import java.sql.SQLException;
017:        import java.sql.Types;
018:
019:        import workbench.log.LogMgr;
020:
021:        public class DbmsOutput {
022:            private Connection conn;
023:            private boolean enabled = false;
024:            private long lastSize;
025:
026:            public DbmsOutput(Connection aConn) throws SQLException {
027:                this .conn = aConn;
028:            }
029:
030:            public void enable(long size) throws SQLException {
031:                if (this .enabled && size == this .lastSize)
032:                    return;
033:                CallableStatement enableStatement = conn
034:                        .prepareCall("begin dbms_output.enable(:1); end;");
035:                enableStatement.setLong(1, size);
036:                enableStatement.executeUpdate();
037:                enableStatement.close();
038:                this .enabled = true;
039:                this .lastSize = size;
040:                LogMgr.logDebug("DbmsOutput.enable()",
041:                        "Support for DBMS_OUTPUT package enabled (max size="
042:                                + size + ")");
043:            }
044:
045:            public void enable() throws SQLException {
046:                this .enable(-1);
047:            }
048:
049:            /*
050:             * disable simply executes the dbms_output.disable
051:             */
052:            public void disable() throws SQLException {
053:                CallableStatement disableStatement = conn
054:                        .prepareCall("begin dbms_output.disable; end;");
055:                disableStatement.executeUpdate();
056:                disableStatement.close();
057:                this .enabled = false;
058:            }
059:
060:            /*
061:             * getResult() does most of the work.  It loops over
062:             * all of the dbms_output data.
063:             */
064:            public String getResult() throws SQLException {
065:                if (!this .enabled)
066:                    return "";
067:                CallableStatement showOutputStatement = conn
068:                        .prepareCall("declare "
069:                                + "    l_line varchar2(255); "
070:                                + "    l_done number; "
071:                                + "    l_buffer long; "
072:                                + "begin "
073:                                + "  loop "
074:                                + "    exit when length(l_buffer)+255 > :maxbytes OR l_done = 1; "
075:                                + "    dbms_output.get_line( l_line, l_done ); "
076:                                + "    l_buffer := l_buffer || l_line || chr(10); "
077:                                + "  end loop; " + " :done := l_done; "
078:                                + " :buffer := l_buffer; " + "end;");
079:
080:                StringBuilder result = new StringBuilder(1024);
081:                try {
082:                    showOutputStatement.registerOutParameter(2, Types.INTEGER);
083:                    showOutputStatement.registerOutParameter(3, Types.VARCHAR);
084:                    for (;;) {
085:                        showOutputStatement.setInt(1, 32000);
086:                        showOutputStatement.executeUpdate();
087:                        result.append(showOutputStatement.getString(3).trim());
088:                        if (showOutputStatement.getInt(2) == 1)
089:                            break;
090:                    }
091:                } finally {
092:                    try {
093:                        showOutputStatement.close();
094:                    } catch (Throwable th) {
095:                    }
096:                }
097:                return result.toString().trim();
098:            }
099:
100:            public void close() {
101:                try {
102:                    this .disable();
103:                } catch (Throwable th) {
104:                }
105:            }
106:
107:            protected void finalize() {
108:                this.close();
109:            }
110:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.