Professional Documents
Culture Documents
In this example we will show you how to connect to MySQL database from your JSP code. First, you need to create
database and then write jsp code to connect jsp to database.
1. Create a database:
First create a database named usermaster in mysql. Before running the jsp code you need to pastemySqlConnector.jar in
lib directory of jdk.
ConnectJspToMysql.jsp
<html>
<head>
<title>Connection with mysql database</title>
</head>
<body>
<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/usermaster";
// declare a connection by using Connection interface
Connection connection = null;