How to connect to MySql using JSP
<%@ 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
{
out.write("Connected!");
}
catch(SQLException e)
{
System.out.println("Error!!!!!!" + e);
}
1) Change 192.168.110 from the above script to your url for e.g. localhost
2) databasename, username and password to your databasename, username and password
Note: Please make sure you already download the mysql-connector for Java
http://dev.mysql.com/downloads/connector/j/
I preferred using Netbeans as IDE for JSP.
No comments:
Post a Comment