Tomcat JSP MySQL Connection Test Script

If you have JSP, MySQL and Jconnector installed, and wanna test if everything works okay, here is a simple script you can use to test.

<%@ page import = "java.sql.*"%> 
<html> 
<head> 
<title>Obtaining a Connection </title> 
</head> 
<body> 
<% 
Connection conn=null; 
ResultSet result=null; 
Statement stmt=null; 
ResultSetMetaData rsmd=null; 
try 
{ 
Class c=Class.forName("com.mysql.jdbc.Driver");
} 
catch(Exception e) 
{ 
out.write("Error!!!!!!" + e); 
} 
try 
{ 
conn=DriverManager.getConnection("jdbc:mysql://192.168.110.5:3306/databasename","username","password");
out.write("Connected!"); 
} 
catch(SQLException e) 
{ 
System.out.println("Error!!!!!!" + e); 
} 

Change 192.168.110 from the above script to your url
databasename, username and password to your databasename, username and password.

Be Sociable, Share!

About Shi Chuan

I am a web developer.
This entry was posted in JSP Core and tagged . Bookmark the permalink.

2 Responses to Tomcat JSP MySQL Connection Test Script

  1. Navneet says:

    Thanks for tutorial, it really helped.

  2. Titan says:

    I have been exploring for a bit for any high quality articles or blog posts on this kind of space . Exploring in Yahoo I eventually stumbled upon this web site. Studying this information So i am glad to express that I’ve a very just right uncanny feeling I found out exactly what I needed. I most indubitably will make sure to do not omit this site and give it a glance regularly.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>