
Java
// your database included with useractive account.
//

MySQL
// You are free to use this code in any way you chose
import Java.io.*;
import Javax.servlet.*;
import Javax.servlet.http.*;
import Java.sql.*;
public
class HelloWorldServlet extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
out.println("<html>");
out.println("<head><title>Hello World</title></head>");
out.println("<body>");
try {
// The newInstance() call is a work around for some
// broken Java implementations
out.println("asdf");
Class.forName("org.gjt.mm.MySQL.Driver").newInstance();
}
catch (Exception E) {
out.println("Unable to load driver.");
E.printStackTrace();
}
out.println("<br><hr>");
try {
Connection Conn =
DriverManager.getConnection("jdbc:MySQL://sql.useractive.com/USERNAME?user=USERNAME&passWord=PASSWord");
// Do something with the Connection
Statement Stmt = Conn.createStatement();
ResultSet RS = Stmt.executeQuery("SELECT * from SOMETABLE");
while (RS.next()) {
out.println(RS.getString(1));
}
// Clean up after ourselves
RS.close();
Stmt.close();
Conn.close();
}
catch (SQLException E) {
out.println("SQLException: " + E.getMessage());
out.println("SQLState: " + E.getSQLState());
out.println("VendorError: " + E.getErrorCode());
}
out.println("<h1>Hello World. Sun... 1.4</h1>");
out.println("</body></html>");
}
public String getServletInfo() {
return "Create a page that says <i>Hello World</i> and send it back";
}
}
Copyright © 2026 eLLeNow.com All Rights Reserved.