這段代码是首页面的<html>
<title><head>校友录</head></title>
<body bgcolor="#aaaddd">
<form action="access.jsp" method="POST">
<BR><BR><BR><BR><BR><BR><BR>
<table border="0" width="20%" align="CENTER">
<tr>姓名:<input type="text" name="username" size=12></tr>
<tr>密码:<input type="text" name="logonword" size=12></tr>
<br>
<tr><input type="submit" value="登 陆" name="Logon" > <input type="button" value="密 码?" name="find" ></tr>
</table>
</form>
</body>
</html>
<title><head>校友录</head></title>
<body bgcolor="#aaaddd">
<form action="access.jsp" method="POST">
<BR><BR><BR><BR><BR><BR><BR>
<table border="0" width="20%" align="CENTER">
<tr>姓名:<input type="text" name="username" size=12></tr>
<tr>密码:<input type="text" name="logonword" size=12></tr>
<br>
<tr><input type="submit" value="登 陆" name="Logon" > <input type="button" value="密 码?" name="find" ></tr>
</table>
</form>
</body>
</html>
<%@page language="java" contentType="html/text;charset=gb2312"%>
<jsp:useBean id="logon1" class="Logon.Access" />
<html>
<head><title>我的校友录</title></head>
<body>
<%
boolean a;
String userName=request.getParameter("username");
String passWord=request.getParameter("logonword");
logon1.connect();
%></body>
</html>
package Logon;
import java.sql.*;
public class Access {
String strerror;
Connection con;
public Access() {}
public void connect() throws ClassNotFoundException,SQLException,Exception{
try{
//Class.forName("jdbc.odbc.JdbcOdbcDriver");
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String strURL="jdbc:oracle:thin:@192.168.15.68:1521:mybase";
//mybase为你的数据库的SID
String user="xugd";
String password="xugd";
con=DriverManager.getConnection(strURL,user,password);
}
catch (ClassNotFoundException cnfe) {
strerror="ClassNotFoundException:could not locate DB driver";
throw new ClassNotFoundException(strerror);
}
catch (SQLException se) {
strerror="SQLException:could not connect to database.";
throw new SQLException(strerror);
}
catch (Exception e) {
strerror="Exception:An unknown error occurred while connection to database";
throw new Exception(strerror);
}
}
//断开ora连接
public void disconnect() throws SQLException {
try{
if(con!=null){
con.close();
}
} catch (SQLException sqle) {
strerror="SQLException:unable to close the database connection.";
throw new SQLException(strerror);
}
}
//判断用户
public boolean UserWord(String userName,String passWord)
throws SQLException,Exception {
ResultSet rs=null;
//Boolean boolSel=false;
if (con!=null) {
try{
String strQuery="select * from myuser where username='"+userName+"' and password='"+passWord+"'";
Statement stmt=con.createStatement();
rs=stmt.executeQuery(strQuery);
if (rs.getFetchSize()>0) {
return true;
}
} catch (SQLException se) {
strerror="SQLException:连接错误!";
throw new SQLException(strerror);
} catch (Exception e) {
strerror="AN ERROR!!!!!!!!!!!";
throw new Exception(strerror);
}
}
return false;
}
}