Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
- {
- response.setContentType("text/html;charset=UTF-8");
- try (PrintWriter out = response.getWriter())
- {
- Connection c = MySQLConnector.connect("DBFoobar", "username", "passwd");
- String message = null;
- if (c == null)
- message = "Connection returned null";
- else
- message = "C is returned: " + c.toString();
- out.println("<!DOCTYPE html>");
- out.println("<html>");
- out.println("<body>");
- out.println(message);
- .
- .
- .
- public class MySQLConnector
- {
- private static final String dbURLPrefix
- = "jdbc:mysql://dbfoobar.xxx.uswest2.rds.amazonaws.com:3306/";
- public static Connection connect(String dbName, String username, String password)
- {
- Connection connection = null;
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection(dbURLPrefix + dbName
- + "?useUnicode=yes&characterEncoding=UTF-8&useSSL=false", username, password);
- .
- .
- .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement