Source Code Cross Referenced for SqlUtils.java in  » Database-JDBC-Connection-Pool » c3p0 » com » mchange » v2 » sql » 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 JDBC Connection Pool » c3p0 » com.mchange.v2.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Distributed as part of c3p0 v.0.9.1.2
003:         *
004:         * Copyright (C) 2005 Machinery For Change, Inc.
005:         *
006:         * Author: Steve Waldman <swaldman@mchange.com>
007:         *
008:         * This library is free software; you can redistribute it and/or modify
009:         * it under the terms of the GNU Lesser General Public License version 2.1, as 
010:         * published by the Free Software Foundation.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public License
018:         * along with this software; see the file LICENSE.  If not, write to the
019:         * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020:         * Boston, MA 02111-1307, USA.
021:         */
022:
023:        package com.mchange.v2.sql;
024:
025:        import java.sql.*;
026:        import com.mchange.v2.log.*;
027:
028:        import java.util.Date;
029:        import java.text.DateFormat;
030:        import java.text.SimpleDateFormat;
031:        import com.mchange.lang.ThrowableUtils;
032:        import com.mchange.v2.lang.VersionUtils;
033:
034:        public final class SqlUtils {
035:            final static MLogger logger = MLog.getLogger(SqlUtils.class);
036:
037:            // protected by SqlUtils.class' lock
038:            final static DateFormat tsdf = new SimpleDateFormat(
039:                    "yyyy-MM-dd HH:mm:ss.SSSS");
040:
041:            public final static String DRIVER_MANAGER_USER_PROPERTY = "user";
042:            public final static String DRIVER_MANAGER_PASSWORD_PROPERTY = "password";
043:
044:            public static String escapeBadSqlPatternChars(String s) {
045:                StringBuffer sb = new StringBuffer(s);
046:                for (int i = 0, len = sb.length(); i < len; ++i)
047:                    if (sb.charAt(i) == '\'') {
048:                        sb.insert(i, '\'');
049:                        ++len;
050:                        i += 2;
051:                    }
052:                return sb.toString();
053:            }
054:
055:            public synchronized static String escapeAsTimestamp(Date date) {
056:                return "{ts '" + tsdf.format(date) + "'}";
057:            }
058:
059:            public static SQLException toSQLException(Throwable t) {
060:                return toSQLException(null, t);
061:            }
062:
063:            public static SQLException toSQLException(String msg, Throwable t) {
064:                return toSQLException(msg, null, t);
065:            }
066:
067:            public static SQLException toSQLException(String msg,
068:                    String sqlState, Throwable t) {
069:                if (t instanceof  SQLException) {
070:                    if (Debug.DEBUG && Debug.TRACE == Debug.TRACE_MAX
071:                            && logger.isLoggable(MLevel.FINER)) {
072:                        SQLException s = (SQLException) t;
073:                        StringBuffer tmp = new StringBuffer(255);
074:                        tmp
075:                                .append("Attempted to convert SQLException to SQLException. Leaving it alone.");
076:                        tmp.append(" [SQLState: ");
077:                        tmp.append(s.getSQLState());
078:                        tmp.append("; errorCode: ");
079:                        tmp.append(s.getErrorCode());
080:                        tmp.append(']');
081:                        if (msg != null)
082:                            tmp.append(" Ignoring suggested message: '" + msg
083:                                    + "'.");
084:                        logger.log(MLevel.FINER, tmp.toString(), t);
085:
086:                        SQLException s2 = s;
087:                        while ((s2 = s2.getNextException()) != null)
088:                            logger.log(MLevel.FINER,
089:                                    "Nested SQLException or SQLWarning: ", s2);
090:                    }
091:                    return (SQLException) t;
092:                } else {
093:                    if (Debug.DEBUG) {
094:                        //t.printStackTrace();
095:                        if (logger.isLoggable(MLevel.FINE))
096:                            logger.log(MLevel.FINE,
097:                                    "Converting Throwable to SQLException...",
098:                                    t);
099:                    }
100:
101:                    if (msg == null)
102:                        msg = "An SQLException was provoked by the following failure: "
103:                                + t.toString();
104:                    if (VersionUtils.isAtLeastJavaVersion14()) {
105:                        SQLException out = new SQLException(msg);
106:                        out.initCause(t);
107:                        return out;
108:                    } else
109:                        return new SQLException(msg
110:                                + System.getProperty("line.separator")
111:                                + "[Cause: "
112:                                + ThrowableUtils.extractStackTrace(t) + ']',
113:                                sqlState);
114:                }
115:            }
116:
117:            private SqlUtils() {
118:            }
119:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.