How to check sample connection string in JSP in Java Reseller Hosting Plan

Please find the below article which describes the sample connection string coding in JSP in Java Reseller Hosting Plan.

You can also refer the below sample jsp coding,

CODING:

<%@ page import=”java.sql.*” %> <%@ page import=”java.io.*” %>


Connection with mysql database

Connection status

<%
try {
/* Create string of connection url within specified format with machine name,
port number and database name. Here machine name id localhost and
database name is usermaster. */
String connectionURL = “jdbc:mysql://localhost:3306/username_DBname”;

// declare a connection by using Connection interface
Connection connection = null;

// Load JBBC driver “com.mysql.jdbc.Driver”
Class.forName(“com.mysql.jdbc.Driver”).newInstance();

/* Create a connection by using getConnection() method that takes parameters of
string type connection url, user name and password to connect to database. */
connection = DriverManager.getConnection(connectionURL, “username_DBusername”, “password”);

// check weather connection is established or not by isClosed() method
if(!connection.isClosed())
%>
<% out.println(“Successfully connected to ” + “MySQL server using TCP/IP…”); connection.close(); } catch(Exception ex){ %>
<% out.println(“Unable to connect to database.”); } %>

In this coding you have to replace the username_DBname and username_DBusername with your DBname and DBusername in Java Reseller Hosting Plan.

Kindly check the below url to confirm whether the connection string is working or not.

http://domainname/dbcheck.jsp

It will show the result as “Successfully Connected”

Hope this will be useful for you to check the JSP connection string.