| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| XMLExport |
|
| 4.0;4 |
| 1 | /** | |
| 2 | * Copyright 2008 WebPhotos | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package net.sf.webphotos.tools; | |
| 17 | ||
| 18 | import java.sql.*; | |
| 19 | ||
| 20 | /** | |
| 21 | * Classe responsável por exportações no formato XML. Os dados são trabalhados | |
| 22 | * somente no método principal, com conexão ao banco. | |
| 23 | */ | |
| 24 | 0 | public class XMLExport { |
| 25 | ||
| 26 | /** | |
| 27 | * Segue algumas rotinas para exportar ao formato XML. Primeiro executa uma | |
| 28 | * conexão com banco de dados, caso não realizado com sucesso, retorna | |
| 29 | * mensagem de erro. Após a conexão estabelecida, começa a gerar o xml. | |
| 30 | * Executa uma query para buscar os dados e os imprime. Essa última parte | |
| 31 | * não está finalizada. | |
| 32 | * | |
| 33 | * @param a Argumentos do método main. | |
| 34 | */ | |
| 35 | public static void main(String a[]) { | |
| 36 | 0 | Connection conn = null; |
| 37 | Statement st1; | |
| 38 | ||
| 39 | try { | |
| 40 | 0 | Class.forName("com.mysql.jdbc.Driver").newInstance(); |
| 41 | 0 | System.out.println("driver carregado"); |
| 42 | 0 | conn = DriverManager.getConnection("jdbc:mysql://192.168.100.1/saopaulo", "root", ""); |
| 43 | 0 | } catch (Exception e) { |
| 44 | 0 | System.out.println("-------------------------------------------------------------------"); |
| 45 | 0 | System.out.println("BancoImagem.erro: nao foi possivel carregar o driver do banco de dados"); |
| 46 | 0 | System.out.println(" erro: " + e.toString()); |
| 47 | 0 | System.out.println("-------------------------------------------------------------------"); |
| 48 | 0 | System.exit(0); |
| 49 | 0 | } |
| 50 | ||
| 51 | ||
| 52 | ||
| 53 | // começa a gerar o xml | |
| 54 | try { | |
| 55 | 0 | String sql1 = "select albumID, nmCategoria, nmAlbum, descricao, DATE_FORMAT(dtInsercao,'%d/%m/%y') as dtInsercao from albuns left join categorias using (categoriaID) limit 10"; |
| 56 | 0 | st1 = conn.createStatement(); |
| 57 | 0 | ResultSet rs1 = st1.executeQuery(sql1); |
| 58 | 0 | while (rs1.next()) { |
| 59 | 0 | System.out.println(rs1.getString("descricao")); |
| 60 | } | |
| 61 | 0 | rs1.close(); |
| 62 | 0 | st1.close(); |
| 63 | 0 | conn.close(); |
| 64 | ||
| 65 | 0 | } catch (Exception ex) { |
| 66 | 0 | } |
| 67 | ||
| 68 | ||
| 69 | 0 | } |
| 70 | } |