Java EE Connection Database exercises

Source: Internet
Author: User

Login Port

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >card number:<input type=" text "name=" cardid1 "><br> password:<input type= "Password" name= "Password1" ><br><input type= "submit" value= "Login" ></form>></body >

Connection request Side

<% @pageImport= "Com.web.cardDAO"%><%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding= "UTF-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >String Cardid=request.getparameter ("Cardid1"); String Password=request.getparameter ("Password1");if(cardid==NULL|| password==NULL|| Cardid.equals ("") | | Password.equals ("") {out.write ("Please log into the system correctly");}Else{    //Check login InformationCarddao cd=NewCarddao (); if(Cd.checklogin (cardid, password)) {Out.write ("Login Successful"); }    Else{out.write ("Login Failed"); }}%></body>

Java code class

Package Com.web;import Java.sql.connection;import Java.sql.preparedstatement;import java.sql.resultset;import Java.sql.sqlexception;import Com.mchange.v2.c3p0.combopooleddatasource;public class CardDAO {ComboPooledDataSource Cpd=new Combopooleddatasource ("helloc3p0");p ublic boolean checklogin (String cardid,string password) {Boolean boo= false;try {Connection conn=cpd.getconnection (); PreparedStatement ps=conn.preparestatement ("SELECT * from bank where ba_card=?") and ba_password=? "); Ps.setstring (1, Cardid);p s.setstring (2, password); ResultSet rs=ps.executequery (); Boo=rs.next (); Rs.close ();p s.close (); Conn.close (); Cpd.close ();} catch (SQLException e) {//TODO auto-generated catch block E.printstacktrace ();} return boo;}}

  

Java EE Connection Database exercises

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.