CODE Connect Jsp to MySQL

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN””&gt;

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

<title>Connection with mysql database</title>
<h1>Connection status</h1>
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/student”;

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

// Load JBBC driver “com.mysql.jdbc.Driver”

/* 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, “root”, “root”);

// check weather connection is established or not by isClosed() method
<font size=”+3″ color=”green”></b>
out.println(“Successfully connected to ” + “MySQL server using TCP/IP…”);
catch(Exception ex){
<font size=”+3″ color=”red”></b>
out.println(“Unable to connect to database.”);


Leave a Reply to assist you..

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s