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 { if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) { Class.forName("com.mysql.jdbc.GoogleDriver"); url = "jdbc:google:mysql://test-123:myInstance/myDatabase?user=root&useUnicode=true&characterEncoding=UTF-8"; } else { Class.forName("com.mysql.jdbc.Driver"); url = "jdbc:mysql://1.2.3.4:3306/myDatabase?user=root&password=test"; } Connection connection = DriverManager.getConnection(url); try (Statement statement = connection.createStatement()) { ResultSet resultSet = statement.executeQuery("select test from tableTest;"); while (resultSet.next()) { out.println(resultSet.getString(1)); } } }catch(Exception ex){ out.println("Exception:" + ex.toString()); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)