- AWS Code Sample

/* Copyright, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class ConnectionHelper { private String url; private static ConnectionHelper instance; private ConnectionHelper() { url = "localhost:3306/mydb"; } public static Connection getConnection() throws SQLException { if (instance == null) { instance = new ConnectionHelper(); } try { Class.forName("com.mysql.jdbc.Driver").newInstance(); return DriverManager.getConnection(instance.url, "root","root1234"); } catch (SQLException | ClassNotFoundException | InstantiationException | IllegalAccessException e) { e.getStackTrace(); } return null; } public static void close(Connection connection) { try { if (connection != null) { connection.close(); } } catch (SQLException e) { e.printStackTrace(); } } }