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
|
<%@ page errorPage="error.jsp" import="java.sql.*" %>
<%! // --------------- inits for the servlet --------------
// The database connection
Connection con;
// The statement
Statement stmt;
// The queryString
String queryString = "drop table table_name";
// ---- configure this for your site
String username = "log";
String password = "pass";
// The URL to connect to Mysql
String url = "jdbc:mysql://ip_host:3306/base_name";
%>
<%
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 ("Ok, connection to the DB is working.");
} catch (Exception e) // (ClassNotFoundException and SQLException){
throw(new UnavailableException(this, "Sorry! The Database didn't load!"));
}
try {
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(queryString); // dernière étape
} catch (SQLException ex ) {} |
Partager