Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Error sqlException:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
- Communications link failure The last packet sent successfully to the server was 0
- milliseconds ago. The driver has not received any packets from the server.
- public class HelloServlet extends HttpServlet {
- @Override
- public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
- PrintWriter out = resp.getWriter();
- //out.println("Dear vistor, you are accessing my first project deployed on cloud. Thank you");
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String url = String.format("jdbc:mysql://IP:3306/DatabaseName?useSSL=false&useUnicode=true&characterEncoding=UTF-8");
- Connection connection = DriverManager.getConnection(url, "userName", "Password");
- try (Statement statement = connection.createStatement()) {
- ResultSet resultSet = statement.executeQuery("select test from tableTest;");
- while (resultSet.next()) {
- out.println(resultSet.getString(1));
- }
- }
- } catch (ClassNotFoundException ex) {
- out.println("Error ClassNotFoundException:" + ex.toString());
- } catch (SQLException ex) {
- out.println("Error sqlException:" + ex.toString());
- }
- catch(Exception ex){
- out.println("Exception:" + ex.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement