Package Test;
Import Java. SQL. * ;
Public Class Conn
{
Static String data = " JDBC: mysql: // localhost/first " ;
Static Java. SQL. Statement st;
Public Static Void Databaseconnect ()
{ // Function used to connect to the database
Try
{
Class. forname ("Com. MySQL. JDBC. Driver");
Connection Conn=Drivermanager. getconnection (data,"Root","Root");
St=Conn. createstatement ();
}
Catch (Exception E)
{
System. Out. println ("Exception:"+E. tostring ());
}
}
Public Static String pwquery (string name)
{
Databaseconnect ();
String inname = Name;
String pw = "" ;
Resultset rs = Null ;
Try
{
RS = (Java. SQL. Statement) stanc.exe cutequery ( " Select * From Test2 where name =' " + Name + " ' " );
While (Rs. Next ())
{
PW=Rs. getstring ("Pass");
}
Rs. Close ();
St. Close ();
// PW = "ABC ";
}
Catch (Sqlexception E)
{
E. printstacktrace ();
}
Return PW;
}
} <? XML version = "1.0" encoding = "gb2312" ?>
<% @ Page Language="Java"Contenttype="Text/html; charset = gb2312" %>
<% @ Page Import="Test. Conn" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head >
< Meta HTTP-equiv = "Content-Type" Content = "Text/html; charsets = ISO-8859-1" />
< Title > Test </ Title >
</ Head >
< Body >
<%
String Temp = ( String ) Session. getvalue ( " Login " );
Temp = Conn. pwquery ( " Admin " );
// Out. Print (temp );
Out. Print (temp );
%>
</ Body >
</ Html >
Note that Tomcat \ common \ Lib
Add
Mysql-connector-java-5.0.8-bin.jar