A simple Java servlet that looks for some well known databases drivers.
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestDB extends HttpServlet {
public void tryDataBase(String name, String url, PrintWriter out){
String fail = "fail";
String sucess = "Ok";
out.println("Looking for the "+ name +" driver...");
try {
Class.forName(url);
out.println(sucess);
} catch (ClassNotFoundException ex) {
out.println(fail);
}
out.println("
");
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("Looking for databases");
out.println("
Looking for databases
");
tryDataBase("MySQL", "com.mysql.jdbc.Driver", out);
tryDataBase("Derby", "org.apache.derby.jdbc.EmbeddedDriver", out);
tryDataBase("PostgreSQL", "org.postgresql.Driver", out);
tryDataBase("Oracle", "oracle. jdbc.driver.OracleDriver", out);
tryDataBase("SQLite", "org.sqlite.JDBC", out);
out.println("");
} finally {
out.close();
}
}
}
When compiling and running this make sure you put your drivers in your classpath.
A example of output:
[…] installing and configuring it you can test the jdbc driver throught this servlet code. You can optionally register the MySQL on NetBeans to have a easier access to it thought the […]