[queryviewer-devel] queryviewer/src/net/sourceforge/queryviewer JDBCConnectionImpl.java,1.6,1.7
Status: Alpha
Brought to you by:
avdyk
From: Arnaud V. <av...@us...> - 2004-06-23 15:32:39
|
Update of /cvsroot/queryviewer/queryviewer/src/net/sourceforge/queryviewer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28314 Modified Files: JDBCConnectionImpl.java Log Message: changement du type de connexion. Maintenant, java.sql.Connection Index: JDBCConnectionImpl.java =================================================================== RCS file: /cvsroot/queryviewer/queryviewer/src/net/sourceforge/queryviewer/JDBCConnectionImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** JDBCConnectionImpl.java 23 Jun 2004 13:46:06 -0000 1.6 --- JDBCConnectionImpl.java 23 Jun 2004 15:32:31 -0000 1.7 *************** *** 5,8 **** --- 5,9 ---- import java.sql.ResultSetMetaData; import java.sql.SQLException; + import java.sql.Connection; /** *************** *** 11,58 **** * @version $Id$ */ ! public class JDBCConnectionImpl implements net.sourceforge.queryviewer.Connection { ! ! private java.sql.Connection connection; ! private String info; ! ! /** ! * Construction d'un objet qui va permettre de trouver les requêtes de l'utilisateur. ! * ! * @param driver le pilote de la base de données ! * @param url l'url de la base de données ! * @param username le nom d'utilisateur pour se connecter à la base de données ! * @param password le mot de passe pour se connecter à la base de données ! * @throws ClassNotFoundException Si le pilote n'a pas été trouvé ! * @throws java.sql.SQLException Si la connexion n'a pu être établie ! */ ! public JDBCConnectionImpl( String driver, String url, String username, String password) ! throws QueryException { ! super(); ! try { Class.forName( driver ); this.connection = java.sql.DriverManager.getConnection( url, username, password ); this.info = prepareInfo(); ! } catch( ClassNotFoundException cnf ) { this.info = cnf.toString(); throw new QueryException( cnf ); ! } catch( java.sql.SQLException sqlex ) { this.info = sqlex.toString(); throw new QueryException( sqlex ); } ! } ! ! /** ! * Exécution de la requête. ! * @param q la requête ! * @return un tableau à deux dimensions contenant les lignes et les colonnes de la requête ! */ ! public synchronized String[][] performQuery(String queryString) ! throws QueryException { ! String[][] data = null; java.sql.Statement stmt = null; ! try { stmt = this.connection.createStatement(); ! if ( stmt.execute( queryString ) ) { // resultset java.sql.ResultSet rs = stmt.getResultSet(); --- 12,67 ---- * @version $Id$ */ ! public class JDBCConnectionImpl implements net.sourceforge.queryviewer.Connection ! { ! ! private java.sql.Connection connection; ! private String info; ! ! /** ! * Construction d'un objet qui va permettre de trouver les requêtes de l'utilisateur. ! * ! * @param driver le pilote de la base de données ! * @param url l'url de la base de données ! * @param username le nom d'utilisateur pour se connecter à la base de données ! * @param password le mot de passe pour se connecter à la base de données ! * @throws ClassNotFoundException Si le pilote n'a pas été trouvé ! * @throws java.sql.SQLException Si la connexion n'a pu être établie ! */ ! public JDBCConnectionImpl( String driver, String url, String username, String password) ! throws QueryException ! { ! super(); ! try ! { Class.forName( driver ); this.connection = java.sql.DriverManager.getConnection( url, username, password ); this.info = prepareInfo(); ! } catch( ClassNotFoundException cnf ) ! { this.info = cnf.toString(); throw new QueryException( cnf ); ! } catch( java.sql.SQLException sqlex ) ! { this.info = sqlex.toString(); throw new QueryException( sqlex ); } ! } ! ! /** ! * Exécution de la requête. ! * @param q la requête ! * @return un tableau à deux dimensions contenant les lignes et les colonnes de la requête ! */ ! public synchronized String[][] performQuery(String queryString) ! throws QueryException ! { ! String[][] data = null; java.sql.Statement stmt = null; ! try ! { stmt = this.connection.createStatement(); ! if ( stmt.execute( queryString ) ) ! { // resultset java.sql.ResultSet rs = stmt.getResultSet(); *************** *** 61,130 **** ar.add(title); int cols = title.length; ! while(rs.next()) { String[] row=new String[cols]; ! for(int i=0; i<cols; i++) { row[i]=rs.getString(i+1); } ar.add(row); } ! if(!ar.isEmpty()) { data=new String[ar.size()][cols]; data=(String[][])ar.toArray(data); } } // end of if () ! else { // int int count = stmt.getUpdateCount(); String scount = String.valueOf( count ); ! data = new String[][] { { "Nombre de fiches mises a jour..." }, { scount } }; } // end of if () else ! } catch(SQLException sqlex) { ! throw new QueryException(sqlex); ! } finally { try ! { ! stmt.close(); ! } catch (SQLException sqlex) ! { throw new QueryException(sqlex); ! } } ! return data; ! } ! ! /** ! * Retourne le nom des colonnes ! * @param metaData les méta données de la requête ! * @return un tableau contenant les noms des colonnes ! */ ! private String[] getColumnNames(ResultSetMetaData metaData) ! throws SQLException { ! String[] title=null; ! int col=metaData.getColumnCount(); ! title=new String[col]; ! for(int i=0; i<col; i++) { // le comptage des colonnes commence à 1 ! title[i]=metaData.getColumnName(i+1); ! } ! return title; ! } ! ! /** * Retourne une description du driver JDBC. ! * @see net.sourceforge.queryviewer.Connection#getInfo() ! */ ! public String getInfo() { ! return this.info; ! } ! /** Préparation des informations sur le driver. * @return les informations */ ! protected String prepareInfo() { StringBuffer stb = new StringBuffer( "JDBC Driver Informations\n" ); ! try { DatabaseMetaData dbmd = this.connection.getMetaData(); stb.append( "Product Name: " + dbmd.getDatabaseProductName() + "\n" ); --- 70,153 ---- ar.add(title); int cols = title.length; ! while(rs.next()) ! { String[] row=new String[cols]; ! for(int i=0; i<cols; i++) ! { row[i]=rs.getString(i+1); } ar.add(row); } ! if(!ar.isEmpty()) ! { data=new String[ar.size()][cols]; data=(String[][])ar.toArray(data); } } // end of if () ! else ! { // int int count = stmt.getUpdateCount(); String scount = String.valueOf( count ); ! data = new String[][] ! { ! { "Nombre de fiches mises a jour..." }, ! { scount } }; } // end of if () else ! } catch(SQLException sqlex) ! { ! throw new QueryException(sqlex); ! } finally ! { try ! { ! stmt.close(); ! } catch (SQLException sqlex) ! { throw new QueryException(sqlex); ! } } ! return data; ! } ! ! /** ! * Retourne le nom des colonnes ! * @param metaData les méta données de la requête ! * @return un tableau contenant les noms des colonnes ! */ ! private String[] getColumnNames(ResultSetMetaData metaData) ! throws SQLException ! { ! String[] title=null; ! int col=metaData.getColumnCount(); ! title=new String[col]; ! for(int i=0; i<col; i++) ! { // le comptage des colonnes commence à 1 ! title[i]=metaData.getColumnName(i+1); ! } ! return title; ! } ! ! /** * Retourne une description du driver JDBC. ! * @see net.sourceforge.queryviewer.Connection#getInfo() ! */ ! public String getInfo() ! { ! return this.info; ! } ! /** Préparation des informations sur le driver. * @return les informations */ ! protected String prepareInfo() ! { StringBuffer stb = new StringBuffer( "JDBC Driver Informations\n" ); ! try ! { DatabaseMetaData dbmd = this.connection.getMetaData(); stb.append( "Product Name: " + dbmd.getDatabaseProductName() + "\n" ); *************** *** 136,148 **** stb.append( "Schemas:\n---------\n " ); ResultSet sches = dbmd.getSchemas(); ! while(sches.next()) { stb.append( sches.getString(1) + "\n" ); } stb.append( "Catalogs:\n---------\n " ); ResultSet cats = dbmd.getCatalogs(); ! while(cats.next()) { stb.append( cats.getString(1) + "\n" ); } ! } catch ( SQLException sqle ) { stb.append( sqle.toString() ); } // end of try-catch --- 159,174 ---- stb.append( "Schemas:\n---------\n " ); ResultSet sches = dbmd.getSchemas(); ! while(sches.next()) ! { stb.append( sches.getString(1) + "\n" ); } stb.append( "Catalogs:\n---------\n " ); ResultSet cats = dbmd.getCatalogs(); ! while(cats.next()) ! { stb.append( cats.getString(1) + "\n" ); } ! } catch ( SQLException sqle ) ! { stb.append( sqle.toString() ); } // end of try-catch *************** *** 150,161 **** return stb.toString(); } ! ! public void close() throws QueryException { ! try { this.connection.close(); ! } catch(SQLException sqlex) { throw new QueryException( sqlex ); } } } --- 176,195 ---- return stb.toString(); } ! ! public void close() throws QueryException ! { ! try ! { this.connection.close(); ! } catch(SQLException sqlex) ! { throw new QueryException( sqlex ); } } + public Connection getConnection() + { + return this.connection; + } + } |