public tituloDP get_grupo(String titulo){
// connection instance
Connection connection = null;
int band=0;
// instance of SubjectName used to retain retrieved data
tituloDP tit = new tituloDP();
try {
// connect to database
Class.forName("com.mysql.jdbc.Driver");
connection=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/a1","admin" ,"admin");
Statement psc=(Statement) connection.createStatement();
ResultSet rsc = (ResultSet) psc.executeQuery("SELECT distinct(des_col) FROM regiones r, titulos t, columnas c, filas f, titxcol tc, titxfil tf, mat_t m where nom_tit=('"+titulo+"') and r.cod_reg=t.cod_reg and t.cod_tit = tc.cod_tit and t.cod_tit=tf.cod_tit and c.cod_col=tc.cod_col and f.cod_fil=tf.cod_fil and tc.cdo_txc=m.cdo_txc and tf.cod_txf=m.cod_txf Order by c.des_col;");
ResultSet Numrsc = (ResultSet) psc.executeQuery("SELECT count(distinct(des_col)) FROM regiones r, titulos t, columnas c, filas f, titxcol tc, titxfil tf, mat_t m where nom_tit=('"+titulo+"') and r.cod_reg=t.cod_reg and t.cod_tit = tc.cod_tit and t.cod_tit=tf.cod_tit and c.cod_col=tc.cod_col and f.cod_fil=tf.cod_fil and tc.cdo_txc=m.cdo_txc and tf.cod_txf=m.cod_txf Order by c.des_col;");
// prepare the SQL query to get columns and number of columns
regiones r, titulos t, columnas c, filas f, titxcol tc, titxfil tf, mat_t m where nom_tit=('"+titulo+"') and r.cod_reg=t.cod_reg and t.cod_tit = tc.cod_tit and t.cod_tit=tf.cod_tit and c.cod_col=tc.cod_col and f.cod_fil=tf.cod_fil and tc.cdo_txc=m.cdo_txc and tf.cod_txf=m.cod_txf Order by c.des_col;");
// set up the result set to retain all queried data
rsc.next();
Numrsc.next();
// prepare the SQL query to get rows and number of rows
Statement psf=(Statement) connection.createStatement();
// set up the result set to retain all queried data
ResultSet rsf=(ResultSet)psf.executeQuery("SELECT distinct(des_fil) FROM regiones r, titulos t, columnas c, filas f, titxcol tc, titxfil tf, mat_t m where nom_tit=('"+titulo+"') and r.cod_reg=t.cod_reg and t.cod_tit = tc.cod_tit and t.cod_tit=tf.cod_tit and c.cod_col=tc.cod_col and f.cod_fil=tf.cod_fil and tc.cdo_txc=m.cdo_txc and tf.cod_txf=m.cod_txf Order by f.des_fil;");
ResultSet Numrsf=(ResultSet)psf.executeQuery("SELECT count(distinct(des_fil)) FROM regiones r, titulos t, columnas c, filas f, titxcol tc, titxfil tf, mat_t m where nom_tit=('"+titulo+"') and r.cod_reg=t.cod_reg and t.cod_tit = tc.cod_tit and t.cod_tit=tf.cod_tit and c.cod_col=tc.cod_col and f.cod_fil=tf.cod_fil and tc.cdo_txc=m.cdo_txc and tf.cod_txf=m.cod_txf Order by f.des_fil;");
rsf.next();
Numrsf.next();
//Setear numero de columnas y filas en tituloDP tit
int ncol=Numrsc.getInt(1);
int nfil=Numrsf.getInt(1);
tit.set_ncol(ncol);
tit.set_nfil(nfil);
Numrsc.close();
Numrsf.close();
//setear contenido de columnas y filas en tituloDP tit
int cont1=0;
while(rsc.next())
{
tit.set_columnas(rsc.getString(1),cont1);
cont1++;
rsc.next();
}
rsc.beforeFirst();
cont1=0;
while(rsf.next())
{
tit.set_filas(rsf.getString(1),cont1);
cont1++;
rsf.next();
}
rsf.beforeFirst();
cont1=0;
int cont2=0;
rsc.next();
rsf.next();
String aux=new String();
Statement psd=(Statement) connection.createStatement();
for(int i=0;i<ncol;i++)
for(int j=0;j<nfil;j++)
{
if(rsf.next()!=false)
{
ResultSet rsd = (ResultSet) psd.executeQuery("SELECT m.des_mat FROM regiones r, titulos t, columnas c, filas f, titxcol tc, titxfil tf, mat_t m where nom_tit=('"+titulo+"') and c.des_col=('"+rsc.getString(1)+"')and r.cod_reg=t.cod_reg and f.des_fil=('"+rsf.getString(1)+"') and t.cod_tit = tc.cod_tit and t.cod_tit=tf.cod_tit and c.cod_col=tc.cod_col and f.cod_fil=tf.cod_fil and tc.cdo_txc=m.cdo_txc and tf.cod_txf=m.cod_txf Order by c.des_col;");
rsd.next();
aux=rsd.getString(1);
tit.set_datos(aux,i,j);
rsd.close();
rsf.next();
}
else
{
rsf.beforeFirst();
rsc.next();
}
}
rsc.close();
rsf.close();
connection.close();
}
catch( SQLException ex )
{
System.out.println( "Error: SQLException" );
while (ex != null)
{
System.out.println ("SQLState: " + ex.getSQLState ());
System.out.println ("Mensaje: " + ex.getMessage ());
System.out.println ("Error: " +ex.getErrorCode ());
ex = ex.getNextException();
System.out.println ("");
}
}
catch(Exception e){
System.out.println(e.getMessage());
// close the connection so it can be returned to
// the connection pool then return the list
}
finally{
return tit;
}
}