Source Code Cross Referenced for ConnectionFactory.java in  » Database-Client » prefuse » prefuse » data » io » 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 Client » prefuse » prefuse.data.io.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package prefuse.data.io.sql;
002:
003:        import java.sql.Connection;
004:        import java.sql.DriverManager;
005:        import java.sql.SQLException;
006:
007:        /**
008:         * @author <a href="http://jheer.org">jeffrey heer</a>
009:         */
010:        public class ConnectionFactory {
011:
012:            /** String constant for the commonly used MySQL JDBC driver */
013:            public static final String DRIVER_MYSQL = "com.mysql.jdbc.Driver";
014:            /** String constant for the JDBC/ODBC bridge driver */
015:            public static final String DRIVER_JDBC_OBDC = "sun.jdbc.odbc.JdbcOdbcDriver";
016:
017:            /** Protocol prefix for JDBC URLs */
018:            public static final String PROTOCOL_JDBC = "jdbc:";
019:            /** Sub-protocol prefix for MySQL connections */
020:            public static final String SUBPROTOCOL_MYSQL = "mysql:";
021:            /** Sub-protocol prefix for JDBC/ODBC bridge connections */
022:            public static final String SUBPROTOCOL_JDBC_ODBC = "odbc:";
023:
024:            // ------------------------------------------------------------------------
025:
026:            /**
027:             * Get an instance of the default SQL data handler.
028:             * @return an instance of the default SQL data handler
029:             */
030:            public static SQLDataHandler getDefaultHandler() {
031:                return new DefaultSQLDataHandler();
032:            }
033:
034:            // ------------------------------------------------------------------------
035:            // Generic Connection Methods
036:
037:            /**
038:             * Get a new database connection.
039:             * @param conn the Connection object to the database
040:             * @param handler the data handler to use
041:             * @return a DatabaseDataSource for interacting with the database
042:             * @throws SQLException if an SQL error occurs
043:             */
044:            public static DatabaseDataSource getDatabaseConnection(
045:                    Connection conn, SQLDataHandler handler)
046:                    throws SQLException {
047:                return new DatabaseDataSource(conn, handler);
048:            }
049:
050:            /**
051:             * Get a new database connection, using a default handler.
052:             * @param conn the Connection object to the database
053:             * @return a DatabaseDataSource for interacting with the database
054:             * @throws SQLException if an SQL error occurs
055:             */
056:            public static DatabaseDataSource getDatabaseConnection(
057:                    Connection conn) throws SQLException {
058:                return getDatabaseConnection(conn, getDefaultHandler());
059:            }
060:
061:            /**
062:             * Get a new database connection.
063:             * @param driver the database driver to use, must resolve to a valid Java
064:             * class on the current classpath.
065:             * @param url the url for the database, of the form
066:             * "jdbc:<database_sub_protocol>://&lt;hostname&gt;/&lt;database_name&gt;
067:             * @param user the database username
068:             * @param password the database password
069:             * @param handler the sql data handler to use
070:             * @return a DatabaseDataSource for interacting with the database
071:             * @throws SQLException
072:             * @throws ClassNotFoundException
073:             */
074:            public static DatabaseDataSource getDatabaseConnection(
075:                    String driver, String url, String user, String password,
076:                    SQLDataHandler handler) throws SQLException,
077:                    ClassNotFoundException {
078:                Class.forName(driver);
079:                Connection conn = DriverManager.getConnection(url, user,
080:                        password);
081:                return getDatabaseConnection(conn, handler);
082:            }
083:
084:            /**
085:             * Get a new database connection, using a default handler.
086:             * @param driver the database driver to use, must resolve to a valid Java
087:             * class on the current classpath.
088:             * @param url the url for the database, of the form
089:             * "jdbc:<database_sub_protocol>://&lt;hostname&gt;/&lt;database_name&gt;
090:             * @param user the database username
091:             * @param password the database password
092:             * @return a DatabaseDataSource for interacting with the database
093:             * @throws SQLException
094:             * @throws ClassNotFoundException
095:             */
096:            public static DatabaseDataSource getDatabaseConnection(
097:                    String driver, String url, String user, String password)
098:                    throws SQLException, ClassNotFoundException {
099:                return getDatabaseConnection(driver, url, user, password,
100:                        getDefaultHandler());
101:            }
102:
103:            // ------------------------------------------------------------------------
104:            // Driver Specific Methods
105:
106:            // -- MySQL ---------------------------------------------------------------
107:
108:            /**
109:             * Get a new database connection to a MySQL database.
110:             * @param host the ip address or host name of the database server
111:             * @param database the name of the particular database to use
112:             * @param user the database username
113:             * @param password the database password
114:             * @param handler the sql data handler to use
115:             * @return a DatabaseDataSource for interacting with the database
116:             * @throws SQLException
117:             * @throws ClassNotFoundException
118:             */
119:            public static DatabaseDataSource getMySQLConnection(String host,
120:                    String database, String user, String password,
121:                    SQLDataHandler handler) throws SQLException,
122:                    ClassNotFoundException {
123:                String url = PROTOCOL_JDBC + SUBPROTOCOL_MYSQL + "//" + host
124:                        + "/" + database;
125:                return getDatabaseConnection(DRIVER_MYSQL, url, user, password,
126:                        handler);
127:            }
128:
129:            /**
130:             * Get a new database connection to a MySQL database, using a default
131:             * handler.
132:             * @param host the ip address or host name of the database server
133:             * @param database the name of the particular database to use
134:             * @param user the database username
135:             * @param password the database password
136:             * @return a DatabaseDataSource for interacting with the database
137:             * @throws SQLException
138:             * @throws ClassNotFoundException
139:             */
140:            public static DatabaseDataSource getMySQLConnection(String host,
141:                    String database, String user, String password)
142:                    throws SQLException, ClassNotFoundException {
143:                return getMySQLConnection(host, database, user, password,
144:                        getDefaultHandler());
145:            }
146:
147:        } // end of class ConnectionFactory
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.