KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb > gui > actions > DBConnectAction


1 package org.apache.ojb.tools.mapping.reversedb.gui.actions;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import javax.swing.JOptionPane JavaDoc;
19
20 /**
21  *
22  * @author <a HREF="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
23  * @version $Id: DBConnectAction.java,v 1.1.2.1 2005/12/21 22:32:06 tomdz Exp $
24  */

25 public class DBConnectAction extends javax.swing.AbstractAction JavaDoc
26 {
27     private org.apache.ojb.tools.mapping.reversedb.gui.JFrmMainFrame mainFrame;
28   /** Creates a new instance of DBConnectAction */
29     public DBConnectAction(org.apache.ojb.tools.mapping.reversedb.gui.JFrmMainFrame pmainFrame)
30   {
31     super();
32     mainFrame = pmainFrame;
33   }
34   
35   public void actionPerformed (java.awt.event.ActionEvent JavaDoc actionEvent)
36   {
37     java.sql.Connection JavaDoc conn = connectToDB(mainFrame.getProperty("JDBCDriver", ""),
38                                            mainFrame.getProperty("JDBCURL", ""),
39                                            mainFrame.getProperty("JDBCUsername", ""),
40                                            mainFrame.getProperty("JDBCPassword", "")) ;
41     if (conn != null)
42       mainFrame.setConnection(conn);
43     else
44       new org.apache.ojb.tools.mapping.reversedb.gui.JDlgDBConnection(mainFrame, false, mainFrame).show();
45   }
46
47   private java.sql.Connection JavaDoc connectToDB(String JavaDoc strJDBCDriver, String JavaDoc strJDBCURL,
48     String JavaDoc strUsername, String JavaDoc strPassword)
49   {
50       try
51       {
52           Class.forName(strJDBCDriver); // "com.informix.jdbc.IfxDriver"
53
java.sql.Connection JavaDoc conn =
54             java.sql.DriverManager.getConnection(strJDBCURL,
55                 strUsername, strPassword); // "jdbc:informix-sqli://moon:1526/bci_test:INFORMIXSERVER=ol_bci", "informix", "informix"
56
return conn;
57       }
58       catch (java.sql.SQLException JavaDoc sqlEx)
59       {
60           java.sql.SQLException JavaDoc currentSqlEx = sqlEx;
61           System.out.println (sqlEx.getErrorCode() + ":" + sqlEx.getMessage());
62           while (currentSqlEx.getNextException() != null)
63           {
64             currentSqlEx = currentSqlEx.getNextException();
65             System.out.println (sqlEx.getErrorCode() + ":" + sqlEx.getMessage());
66           }
67           JOptionPane.showMessageDialog(mainFrame, "Error connecting to database:\n" + sqlEx.getMessage(), "SQL Error", JOptionPane.ERROR_MESSAGE);
68           return null;
69       }
70       catch (java.lang.ClassNotFoundException JavaDoc clNotFoundEx)
71       {
72           clNotFoundEx.printStackTrace();
73           JOptionPane.showMessageDialog(mainFrame, "Cannot find driver class:\n" + clNotFoundEx.getMessage(), "Class Not Found", JOptionPane.ERROR_MESSAGE);
74           return null;
75       }
76       catch (Throwable JavaDoc t)
77       {
78           t.printStackTrace();
79           JOptionPane.showMessageDialog(mainFrame, "Unknown error:\n" + t.getMessage(), "Unknown Error", JOptionPane.ERROR_MESSAGE);
80           return null;
81       }
82   }
83 }
84
85 /***************************** Changelog *****************************
86 // $Log: DBConnectAction.java,v $
87 // Revision 1.1.2.1 2005/12/21 22:32:06 tomdz
88 // Updated license
89 //
90 // Revision 1.1 2004/05/05 16:38:11 arminw
91 // fix fault
92 // wrong package structure used:
93 // org.apache.ojb.tools.reversdb
94 // org.apache.ojb.tools.reversdb2
95 //
96 // instead of
97 // org.apache.ojb.tools.mapping.reversdb
98 // org.apache.ojb.tools.mapping.reversdb2
99 //
100 // Revision 1.1 2004/05/04 13:44:59 arminw
101 // move reverseDB stuff
102 //
103 // Revision 1.7 2004/04/05 12:16:24 tomdz
104 // Fixed/updated license in files leftover from automatic license transition
105 //
106 // Revision 1.6 2004/04/04 23:53:42 brianm
107 // Fixed initial copyright dates to match cvs repository
108 //
109 // Revision 1.5 2004/03/11 18:16:23 brianm
110 // ASL 2.0
111 //
112 // Revision 1.4 2003/06/21 10:38:16 florianbruckner
113 // improve error reporting
114 //
115 // Revision 1.3 2002/06/18 12:23:15 florianbruckner
116 // bugfix: was reading a table "CATEGORIES" after opening a connection.
117 //
118 // Revision 1.2 2002/06/17 19:34:34 jvanzyl
119 // Correcting all the package references.
120 // PR:
121 // Obtained from:
122 // Submitted by:
123 // Reviewed by:
124 //
125 // Revision 1.1.1.1 2002/06/17 18:16:54 jvanzyl
126 // Initial OJB import
127 //
128 // Revision 1.2 2002/05/16 11:47:09 florianbruckner
129 // fix CR/LF issue, change license to ASL
130 //
131 // Revision 1.1 2002/04/18 11:44:16 mpoeschl
132 //
133 // move files to new location
134 //
135 // Revision 1.2 2002/04/07 09:05:17 thma
136 // *** empty log message ***
137 //
138 // Revision 1.1.1.1 2002/02/20 13:35:25 Administrator
139 // initial import
140 //
141 /***************************** Changelog *****************************/

142  
143
Popular Tags