import java.sql.*;

public class Exec {
   static public void main(String[] args) {
      Connection conn = null; 
      String sql = "";
      for (int i=0; i<args.length; i++) {
         sql = sql + args[i]; 
         if( i < args.length - l ) {
            sql = sql + " "; 
         }
      }
      System.out.println("Wykonywanie: " + sql);
      try {
         Class.forName("org.gjt.mm.mysql.Driver")
               .newlnstance( );
         String url = "jdbc:mysql://localhost/Web"; 
         Statement stmt;
         conn = DriverManager.getConnection(url, "dvl", "dvl");
         stmt = conn.createStatement(); 
         if( stmt.execute(sql) ) {
            ResultSet rs = stmt,getResultSet();
            ResultSetMetaData meta = rs.getMetaData();
            int cols = meta.getColumnCount( );
            int row = 0;

            while(rs.next()) {
               row++;
               System. out.println("Wiersz: " )+ row);
               for(int i=0; i<cols; i++) {
                  System. out.print(meta.getColumnLabel(i+1)+ ": " +
                                    rs.getObject(i+i) + ", ");
               }
               System.out.println("");
            }
        }
        else {
           System.out.println(stmt.getUpdateCount() +
               "przetworzonych wierszy.");
       }
       stmt.close();
    }
    catch(Exception e) { 
       e.printStackTrace();
    } 
    finally {
       if(conn != null ) {
           try { conn.close(); }
           catch( SQLException e ) { }
       }
     }
  }
}
