CONTENTS OF THIS PART¦¦LIST OF DATA¦¦HOMEPAGE¦¦
WORKPAGE¦¦
TECFA
Insert New Data
<%@ 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 ("login");
String myString2 = request.getParameter ("nom");
String myString3 = request.getParameter ("prenom");
String myString4 = request.getParameter ("password");
queryString = "insert into studentTest values (NULL,'" + myString1 + "','" + myString2 + "','" + myString3 + "','" + myString4 + "')";
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 ("The connection with the database has been estalished.");
} catch (Exception e) // (ClassNotFoundException and SQLException)
{
throw(new UnavailableException(this, "Sorry! The connection with the database has not been connected!"));
}
}
%>
Fill in all the fields and then click on the button "Send your information into the database"