1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
| import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.PreparedStatement;
import com.microsoft.sqlserver.jdbc.*;
import java.net.*;
import java.lang.Runtime;
import java.text.DateFormat;
import java.text.SimpleDateFormat ;
import java.time.Period;
import java.time.ZoneId;
import java.text.ParseException ;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class nomDeLapplication extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
doPost(request, response) ;
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
String SDT=null;
String EDT=null;
String StrError=" ";
Connection ConnBDD1 = null;
Connection BDD2 = null;
DateFormat dtFormat;
boolean autorise = false ;
try
{
try
{
// Connexion à BDD1
SQLServerDataSource ds_easily = new SQLServerDataSource();
ds_easily.setUser(db.User);
ds_easily.setPassword(db.Password);
ds_easily.setServerName(db.ServerName);
ds_easily.setPortNumber(db.PortNumber);
ds_easily.setDatabaseName(db.DatabaseName);
ConnBDD1 = ds_easily.getConnection();
// Connexion à la base "BDD2"
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
BDD2 = DriverManager.getConnection("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=XXXX)(PORT=1521))(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XXXX)(FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC))))", "XXXX", "XXXX");
}
catch (Exception e) {e.printStackTrace ();}
GenerenomDeLapplication(request, response, ConnBDD1, BDD2);
if(ConnBDD1!=null)
ConnBDD1.close();
if(BDD2!=null)
BDD2.close();
}
catch (Exception e) {e.printStackTrace ();}
}
private void GenerenomDeLapplication(HttpServletRequest request, HttpServletResponse response, Connection ConnBDD1, Connection BDD2) throws Exception
{
boolean autorise = false;
int nombreColonnes = 0;
int nb_ligne = 0;
int count = 0;
DateFormat dtFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
SimpleDateFormat dtFormat_t = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
response.setContentType("text/html");
PrintWriter out = response.getWriter ();
Statement stmt1 = ConnBDD1.createStatement();
ResultSet results1 = null ;
/*Récupération des paramètres*/
String iPP = request.getParameter("iPP");
String bouton_valid = request.getParameter("bouton_valid");
if(iPP==null)
iPP="";
if(bouton_valid==null)
bouton_valid="";
out.println("<html><head><title>Mon Application</title>");
out.println("<script type='text/javascript' language='javascript' src='../jquery-3.1.1.min.js'> </script>");
out.println("<script type='text/javascript' language='javascript' src='../DataTables/media/js/jquery.dataTables.min.js'> </script>");
out.println("<script type='text/javascript' language='javascript' src='../DataTables/extensions/Buttons/js/jszip.min.js'> </script>");
out.println("<script type='text/javascript' language='javascript' src='../moment.min.js'> </script>");
out.println("<script type='text/javascript' language='javascript' src='../datetime-moment.js'> </script>");
out.println("<link href='../bootstrap/css/bootstrap.css' rel='stylesheet'>");
out.println("<link href='../DataTables/media/css/jquery.dataTables.min.css' rel='stylesheet'>");
out.println("</head>");
out.println("<body >");
out.println("<form id='idform' method=post>");
out.println("Ipp : <input type='text' name='iPP'> ");
out.println("<INPUT type='submit' class='button' value=\'Rechercher\' name=\'bouton_valid\' >");
out.println("</form>");
if(!bouton_valid.equals("Rechercher")||iPP.equals(""))
{
out.println("Merci de renseigner le champ et de cliquer sur le bouton Rechercher");
}
else //if (bouton_valid.equals("Rechercher"))// si au moins un paramètre est renseigné
{
int maxtab = 0;
int maxLigne = 1000;
int cptCol;
String tab[][] = new String[maxLigne][25];
String sqlText1 = " une belle requete SQL ";
results1 = stmt1.executeQuery(sqlText1);
ResultSetMetaData metadata = results1.getMetaData();
nombreColonnes = metadata.getColumnCount();
tab = new String[maxLigne][nombreColonnes + 2] ;
boolean pasfini1= results1.next ();
//récupération du nom des colonnes
for(int i = 0 ; i < nombreColonnes ; i++)
{
tab[0][i] = metadata.getColumnName(i + 1);
}
// Ajout d'une colonne pour stocker infos supp
tab[0][nombreColonnes] = "UF Affect";
String login = "";
while (pasfini1 && nb_ligne < maxLigne)
{
for(int i=0 ; i < nombreColonnes; i++)
{
tab[count+1][i]=results1.getString(i+1) ;
{
// traitement particulier pour certains champs
}
}
// Requête supplémentaire
Statement stmt2 = BDD2.createStatement();
String sqlText2 = "un belle requete qui ajoute des infos" ;
ResultSet results2 = stmt2.executeQuery(sqlText2);
boolean pasfini2 = results2.next();
boolean isactif = true;
if(pasfini2)
{
listeUf ="je recupere des infos de ma requete";
}
// On stocke la liste des habilitations dans notre tableau
tab[count+1][nombreColonnes] = listeUf;
pasfini1=results1.next();
count++;
maxtab = count;
}
if(maxtab > 0)
{
out.println("<table id='tab_recap' class='display table-condensed compact cell-border' cellspacing='0' width='100%' >");
out.println("<p style='border:1px; border-style:solid; border-color:#0066cc; padding: 0.5em;'>Infos</p>");
out.println("<thead>");
out.println("<tr>");
/* on ecrit les entêtes */
for(cptCol = 0; cptCol <= nombreColonnes; cptCol++)
{
out.println("<th>"+tab[0][cptCol]+"</th>");
}
out.println("</tr>");
out.println("</thead>");
out.println("<tbody>");
for (int i = 1; i < maxtab; i++) // parcours des lignes
{
out.println("<tr>");
for(cptCol = 0; cptCol <= nombreColonnes; cptCol++)
{
out.println("<td>" + tab[i][cptCol] + "</td>");//lit
}
out.println("</tr>");
}
out.println("</tbody>");
out.println("</table>");
out.println("<br>");
}
else
{
out.println("Aucun résultat.");
}
}
//paramétrage data tables
out.println("<script> $(document).ready(function() { ");
out.println("$.fn.dataTable.moment('DD/MM/YYYY');");
out.println("$('#tab_recap').DataTable( {");
out.println("dom: 'Bfrtip',");
out.println("paging: false,");
out.println("order: [[ 1, 'asc' ]], ");
out.println("'language': { 'url': '../DataTables/French.json' } ");
out.println(" });");
out.println(" } ); </script>");
out.println("</body>");
}
} |
Partager