<%@page import="org.apache.tomcat.util.net.SSLUtil"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <html> <head> <title>Connection with mysql database</title> </head> <body> <h1>Connection status </h1> <% try { String connectionURL = "jdbc:mysql://dbno2.cfghe6zvdgnoq7r.ap-southeast-2.rds.amazonaws.com:3306/mydb?user=aghil&password=password1"; Connection connection = null; Statement stmt = null; Class.forName("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager.getConnection(connectionURL); if (!connection.isClosed()) { stmt = connection.createStatement(); } out.println("Successfully connected to MySQL server using TCP/IP...\n"); String QueryString = "select username from mydb.userdetails WHERE username ='anil' and password='password'"; ResultSet rs; String sre = null; try { PreparedStatement statement = connection.prepareStatement(QueryString); rs = statement.executeQuery(); sre = rs.getString(1); out.println("\n" + sre); } catch (Exception e) { out.println("\n" + e.toString()); } connection.close(); } catch (Exception ex) { out.println("Unable to connect to database." + ex); } %> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)