oracle+myeclipse+jsp Implement simple Login function

Source: Internet
Author: User
Tags stmt

Creation of Oracle Database tables:

CREATE TABLE Log (
Un char (20),
PD Char (25)
)
Tablespace users;

Oracle Configuration in MyEclipse:

1. Guide Jar Package:

Right-click the project name, build path→configure build Path→libraries→add External JARs. →d:\app\asus\product\11.2.0\dbhome_1\jdbc\lib (that is, your Oracle installation path \product ... → Select Ojdbc*.jar (* for the jar package version number in your own file) →ok

You can see the item in the jar package import, displayed in the referenced libraries directory.

2. Open the MyEclipse Database Explorer for the Oracle DB connection configuration.

Right-click on a new→driver template select Oracle (Thin Driver) →driver name:oracledriver→connection URL:jdbc:oracle:thin: @localhost :1521:<database_name> (<database_name> Replace with the name of the database to be connected) →user name: User name to log in to the database →password: corresponding password →add JARs (same as the path and the guide package, choose the same version) →driver classname: This is the add JARs automatically generated, note class.forname () must correspond to here →test driversave→ Show Database Connection successfully established indicates a successful connection. (Can save password convenient next test)

3. Write the connection code, good luck.

logincheck.jsp

<%@ page language= "java" import= "java.util.*,java.sql.*" pageencoding= "UTF-8"%>
<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >


<body>
<%
String drivername= "Oracle.jdbc.OracleDriver";
String dburl= "Jdbc:oracle:thin: @localhost: 1521:test";
String username= "System";
String userpwd= "1234";
Connection conn = null;
ResultSet rs = null;
%>


<%
Boolean flag=false;
String user = Request.getparameter ("Usern");
SYSTEM.OUT.PRINTLN (user);
String pass = Request.getparameter ("PASSW");
System.out.println (pass);

try{
Class.forName ("Oracle.jdbc.OracleDriver");
conn = Drivermanager.getconnection ("Jdbc:oracle:thin: @localhost: 1521:test", "System", "1234");
String sql= "SELECT * from Log where un= '" +user+ "' and pd= '" +pass+ "'";
Statement stmt = Conn.createstatement ();
System.out.println ("stmt");
rs = stmt.executequery (SQL);
System.out.println ("RS suc");

if (Rs.next ()) {
SYSTEM.OUT.PRINTLN ("yes");
Flag=true;

}else{
Flag=false;
System.out.println ("no");
}
Rs.close ();
Stmt.close ();
Conn.close ();

}catch (Exception err) {
SYSTEM.OUT.PRINTLN ("error");
}


if (flag) {
%>
<jsp:forward page= "suc.jsp"/>
<%
}else{
%>
<jsp:forward page= "error.jsp"/>
<%
}

%>

</body>

login.jsp (main part only)

<body>

<form action= "logincheck.jsp" method= "POST" >
<table align= "center" >
<tr> <td> user name: <input type= "text" name= "Usern"/></td> </tr>
<tr> <td> Password: <input type= "password" name= "PASSW"/><a href= "find.jsp" > Forgot password? </a> </td></tr>

</table>
</form>

</body>

oracle+myeclipse+jsp Implement simple Login function

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.