[ CONSULTER LES DONNEES] - [ RECHERCHE AVEC REQUETES MYSQL ] - [ HOME ]

INSERTION DE LA NOUVELLE DONNEE

<%@ page errorPage="error.jsp" import="java.sql.*" %> <%! // --------------- inits for the servlet -------------- // Connection à la base de donnée Connection con; // The statement Statement stmt; // The queryString String queryString = null; // ---- configure this for your site String username = "nobody"; String password = null; // The URL that will connect to TECFA's MySQL server // Syntax: jdbc:TYPE:machine:port/DB_NAME // String url = "jdbc:mysql://localhost:3306/staf2x"; String url = "jdbc:mysql://tecfa2.unige.ch:3306/staf2x"; %> <% // --------------- code for the service method -------------- // Let's see if we got a request String myString1 = request.getParameter ("ilogin"); String myString2 = request.getParameter ("inom"); String myString3 = request.getParameter ("iprenom"); String myString4 = request.getParameter ("iadresse"); String myString5 = request.getParameter ("inpa"); String myString6 = request.getParameter ("itel"); String myString7 = request.getParameter ("iportable"); String myString8 = request.getParameter ("iemail"); queryString = "insert into scribante1 values (NULL,'" + myString1 + "','" + myString2 + "','" + myString3 + "','" + myString4 + "','" + myString5 + "','" + myString6 + "','" + myString7 + "','" + myString8 + "')"; if ((queryString != "") && (queryString != null)) { try { Class.forName("org.gjt.mm.mysql.Driver"); // Establish Connection to the database at URL with usename and password con = DriverManager.getConnection(url, username, password); out.println ("La connection avec la base de donnée est établie."); } catch (Exception e) // (ClassNotFoundException and SQLException) { throw(new UnavailableException(this, "Désolé ! la connection à la base de donnée n'est pas établie")); } } %>

OK, la donnée a été enregistrée, appuyez sur le bouton si vous souhaitez enregister une nouvelle donnée

<% try { out.println ( "
"+"

Détails de la requête

"); out.println ( "Requête: " + queryString + "
" ); out.println(""); stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(queryString); ResultSetMetaData rsMeta = rs.getMetaData(); // Get the N of Cols in the ResultSet int noCols = rsMeta.getColumnCount(); out.println(""); for (int c=1; c<=noCols; c++) { String el = rsMeta.getColumnLabel(c); out.println(""); } out.println(""); while (rs.next()) { out.println(""); for (int c=1; c<=noCols; c++) { String el = rs.getString(c); out.println(""); } out.println(""); } out.println("
" + el + "
" + el + "
"); } catch (SQLException ex ) { out.println ( "

" );

while (ex != null) {

out.println("Message: " + ex.getMessage ());

out.println("SQLState: " + ex.getSQLState ());

out.println("ErrorCode: " + ex.getErrorCode ());

ex = ex.getNextException();

out.println("");

}

out.println ( "

" ); } %>


Vanessa Scribante - avril 2000