Hola ,tengo un problema y es que tengo que leer unos datos de un archivo eexcel con java para luego formar una matriz de datos y dibujar un grafico ,tambien con jaja ¿me podeis pasar algo de codigo para ver como se lee un excel?
1 respuesta
Respuesta de joraanma
1
1
joraanma, Desarrollador de Systema, Integraciones, programacion,Java,...
mport java.io.*; import java.sql.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.DriverManager; import java.sql.DatabaseMetaData; /** * * @author admin * @version */ public class Stats { Connection c = null; Statement stmt = null; String team="",action=""; ResultSet rs=null; /*public static void main(String args[]){ Stats st=new Stats(); System.out.println("In main"); try{ st.Actions(); }catch(Exception e){ System.out.println(e.getMessage()); } }*/ public void setTeam(String t){ this.team=t; } public void setAction(String a){ this.action=a; } public String getTeam(){ return this.team; } public String getAction(){ return this.action; } public ResultSet Actions(String dsName)throws Exception { try { Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ); c = DriverManager.getConnection( "jdbc:odbc:csasDS", "joraanma", "jonathan" ); stmt = c.createStatement(); String query = "select * from [main$];"; rs= stmt.executeQuery( query ); }catch(Exception e){ throw e; } /*else if (args.length == 2) { // make sure that we can write to the Excel workbook if (c.isReadOnly()) c.setReadOnly(false); DatabaseMetaData dbmd = c.getMetaData(); ResultSet rs = dbmd.getTables(null, null, args[0], new String[] {"TABLE"}); // drop the table if it already exists while (rs.next()) { System.out.println("dropping table = " + rs.getString("TABLE_NAME")); stmt.execute("drop table [" + args[0] + "];"); } // now create the table (worksheet) StringBuffer sql = new StringBuffer(); sql.append("create table [" + args[0] + "] "); sql.append("(" + args[1] + ")"); System.out.println("sql = " + sql.toString()); System.out.println(stmt.executeUpdate(sql.toString())); } else { // make sure that we can write to the Excel workbook if (c.isReadOnly()) c.setReadOnly(false); // we are expecting to insert four values: // - merchant name // - bill closing day of the month // - type of payment (automatic or manual) // - amount of payment if (args.length == 4) { String payType = new String(); if (args[2].equalsIgnoreCase("0")) payType = "Manual"; else payType = "Automatic"; String sql = new String(); sql = "Insert into [main$] (" + "Merchant, " + "Closing, " + "Type, " + "Amount) values ('" + args[0] + "', '" + args[1] + "', '" + payType + "', '" + args[3] + "')";