Connection with MySQL with JSP in windows environment.
OS : Windows 2000 Server
MySQL version 5.0
Tomcat Version: 5.5
JSP program :-
<%@ page import="java.sql.*" %>
<%
String connectionURL = "jdbc:mysql://localhost:
3306/
sandip?user=
root@localhost&password=
admin";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>
<html><body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance ();
connection = DriverManager.getConnection(connectionURL,"
root","
admin");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT * FROM
pal");
while (rs.next()) {
out.println(rs.getString("
ID"));
out.println(rs.getString("
Name")+"<br>");
}
rs.close();
%>
</body></html>
copy the file âmysql-connector-java-5.0.4-bin.jarâ (it is free downloadable from internet) to tomcat\common\lib folder.
In this program my database name sandip, table name pal. Table pal contains two fields ID and Name.
Description of bold words.
3306: In port number of MySQL.
sandip: database name.
root@localhost: user name (you get the user name from MySQL by giving the command select user();)
admin: password of MySQL.
root: root is user.
pal: table name.
ID: table field1
Name: table field2
Posted By Sandip Pal
Comments:
[email protected]
[u]</u>