This document contains code to connect to a database, execute a SQL query, and write the results to a CSV file. It connects to a DBF database using JDBC, executes a query to get cell IDs, builds a SQL statement to aggregate KPI data by date and cell IDs, executes the statement, writes the column names and row data to a CSV file, and closes all connections.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
78 views1 page
SQL DBF Dbfdriver
This document contains code to connect to a database, execute a SQL query, and write the results to a CSV file. It connects to a DBF database using JDBC, executes a query to get cell IDs, builds a SQL statement to aggregate KPI data by date and cell IDs, executes the statement, writes the column names and row data to a CSV file, and closes all connections.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
Untitled
public void makeConnection() throws Exception {
{ Integer i, columnas; BufferedWriter bw = new BufferedWriter(new FileWriter("KPI_result.csv")); Class.forName("com.caigen.sql.dbf.DBFDriver"); String connString = "jdbc:dbf:/D:/2014/Tools3G/JAVA"; String l = ""; String query; Connection connection = DriverManager.getConnection(connString); String sql = "SELECT Utrancell FROM Celdas.dbf";// usual sql query Statement stmt = connection.createStatement(); ResultSet resultSet = stmt.executeQuery(sql); resultSet.next(); l = "'" + resultSet.getString(1); while (resultSet.next()) { l = l + "','" + resultSet.getString(1); } l = l + "'"; stmt.close(); connection.close(); Connection connection2 = DriverManager.getConnection(connString); Statement stmt2 = connection2.createStatement(); query = "Select DATE_ID,avg(EUL_USER_P) as EUL_User,avg(HS_USER_PE) as HS_User,sum(CORTES_PRO)/sum(INTENTOS_C) as DropCS, " + "sum(CORTES_HS_)/sum(INTENTOS_H) as DropHS,sum(CORTES_EUL)/sum(INTENTOS_E) as DropEUL,sum(CORTES_PS_)/sum(INTENTOS_P) as DropPS, " + "sum(CORTES_FAC)/sum(INTENTOS_F) as DropFACH, avg(MHT_HS_SEG) as MHT_HS, avg(MHT_EUL_SE) as MHT_Eul, avg(ACC_CS_PRO) as ACC_CS, " + "avg(ACC_HS_PRO) as ACC_HS, avg(ACC_EUL_PR) as ACC_EUL from kpi_consol.dbf " + "where Utrancell in (" + l + ") group by DATE_ID"; ResultSet rs = stmt2.executeQuery(query); columnas = rs.getMetaData().getColumnCount(); l = rs.getMetaData().getColumnName(1); for (i = 2; i <= columnas; i++) { l = l + "," + rs.getMetaData().getColumnName(i); } bw.write(l + "\n"); while (rs.next()) { l = rs.getString(1); for (i = 2; i <= columnas; i++) { l = l + "," + rs.getString(i); } bw.write(l + "\n"); } rs.close(); stmt2.close(); bw.close(); connection2.close(); }