数据库连接操作(一)
用纯JSP写的连接数据库操,具体包括数据查询、删除、修改,数据的添加在数据库里操作,数据库为MySQL 文件包括login.jsp,do_login.jsp(处理登录信息),index.jsp(显示登录用户名、密码和编辑删除操作),edit.jsp,do_edit.jsp,delete.jsp 登录页面 login.jsp vc
用纯JSP写的连接数据库操,具体包括数据查询、删除、修改,数据的添加在数据库里操作,数据库为MySQL
文件包括login.jsp,do_login.jsp(处理登录信息),index.jsp(显示登录用户名、密码和编辑删除操作),edit.jsp,do_edit.jsp,delete.jsp
登录页面
login.jsp喎?http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PHByZSBjbGFzcz0="brush:sql;">
欢迎注册该网站
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>登录处理页面</title> </head> <body> <% request.setCharacterEncoding("gb2312"); response.setContentType("text/html;charset=gb2312"); String user=request.getParameter("username"); String pwd=request.getParameter("password"); final String DBDriver="com.mysql.jdbc.Driver"; final String DBUrl="jdbc:mysql://localhost:3306/mqsqltest"; final String DBUser="root"; final String DBPassword="686175"; Connection conn=null; Statement stmt=null; ResultSet rs=null; Class.forName(DBDriver); conn=DriverManager.getConnection(DBUrl,DBUser,DBPassword); String sql="select * from user where username='"+user+"'&&password='"+pwd+"'"; stmt=conn.createStatement(); rs=stmt.executeQuery(sql); if(rs.next()){ out.print("登录成功!"); response.setHeader("refresh","2;url=index.jsp"); } else{ out.println("您登录的账号或密码错误!"); response.setHeader("refresh","2;url=login.jsp"); } stmt.close(); conn.close(); %> </body> </html>

index.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>数据列表</title> </head> <body> <% request.setCharacterEncoding("gb2312"); response.setContentType("text/html;charset=gb2312"); final String DBDriver="com.mysql.jdbc.Driver"; final String DBUrl="jdbc:mysql://localhost:3306/mqsqltest"; final String DBUser="root"; final String DBPassword="686175"; Connection conn=null; Statement stmt=null; ResultSet rs=null; Class.forName(DBDriver); conn=DriverManager.getConnection(DBUrl,DBUser,DBPassword); String sql="select * from user"; stmt=conn.createStatement(); rs=stmt.executeQuery(sql); %> <table border="1"> <tr> <td>编号</td> <td>帐号</td> <td>密码</td> <td>编辑</td> <td>删除</td> </tr> <% while(rs.next()){ %> <tr> <td><%=rs.getInt(1) %></td> <td><%=rs.getString(2) %></td> <td><%=rs.getString(3) %></td> <td><a href="edit.jsp?id=<%=rs.getInt(1)%>">更新</a></td> <td><a href="delete.jsp?id=<%=rs.getInt(1)%>">删除</a></td> </tr> <% } stmt.close(); conn.close(); %> </table> </body> </html>
编辑后
edit.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>编辑页面</title> </head> <body> <% request.setCharacterEncoding("gb2312"); response.setContentType("text/html;charset=gb2312"); int id=Integer.parseInt(request.getParameter("id")); session.setAttribute("id", id); final String DBDriver="com.mysql.jdbc.Driver"; final String DBUrl="jdbc:mysql://localhost:3306/mqsqltest"; final String DBUser="root"; final String DBPassword="686175"; Connection conn=null; Statement stmt=null; ResultSet rs=null; Class.forName(DBDriver); conn=DriverManager.getConnection(DBUrl,DBUser,DBPassword); String sql="select * from user where id='"+id+"'"; stmt=conn.createStatement(); rs=stmt.executeQuery(sql); rs.next(); %> <center> <h3 id="编辑页面">编辑页面</h3> <form action="do_edit.jsp" method="post"> <table> <tr> <td>帐号</td> <td><input type="text" name="username" value=<%=rs.getString(2)%>></td> </tr> <tr> <td>密码</td> <td><input type="password" name="password" value=<%=rs.getString(3)%>></td> </tr> <tr> <td></td> <td> <input type="submit" value="保存"> <input type="reset" value="取消"> </td> </tr> </table> </form> </center> </body> </html>
do_edit.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <%@ page import="java.util.*" %> <html> <head> <title>编辑保存页面</title> </head> <body> <% request.setCharacterEncoding("gb2312"); response.setContentType("text/html;charset=gb2312"); int id=Integer.parseInt(session.getAttribute("id").toString()); String user=request.getParameter("username"); String pwd=request.getParameter("password"); final String DBDriver="com.mysql.jdbc.Driver"; final String DBUrl="jdbc:mysql://localhost:3306/mqsqltest"; final String DBUser="root"; final String DBPassword="686175"; Connection conn=null; Statement stmt=null; ResultSet rs=null; Class.forName(DBDriver); conn=DriverManager.getConnection(DBUrl,DBUser,DBPassword); stmt=conn.createStatement(); if(user!=null&&pwd!=null){ String sql="update user set username='"+user+"',password='"+pwd+"' where id='"+id+"'"; stmt.executeUpdate(sql); out.print("修改成功!"); response.setHeader("refresh","2;url=index.jsp"); }else{ out.print("帐号或密码不能为空!"); response.setHeader("refresh","2;url=edit.jsp"); } %> </body> </html>
delete.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <html> <head> <title>删除页面</title> </head> <body> <% request.setCharacterEncoding("gb2312"); response.setContentType("text/html;charset=gb2312"); int id=Integer.parseInt(request.getParameter("id")); final String DBDriver="com.mysql.jdbc.Driver"; final String DBUrl="jdbc:mysql://localhost:3306/mqsqltest"; final String DBUser="root"; final String DBPassword="686175"; Connection conn=null; Statement stmt=null; Class.forName(DBDriver); conn=DriverManager.getConnection(DBUrl,DBUser,DBPassword); String sql="delete from user where id='"+id+"'"; stmt=conn.createStatement(); stmt.executeUpdate(sql); stmt.close(); conn.close(); out.print("删除成功!"); response.setHeader("refresh","2;url=index.jsp"); %> </body> </html>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

Ele.me is a software that brings together a variety of different delicacies. You can choose and place an order online. The merchant will make it immediately after receiving the order. Users can bind WeChat through the software. If you want to know the specific operation method , remember to check out the PHP Chinese website. Instructions on how to bind WeChat to Ele.me: 1. First open the Ele.me software. After entering the homepage, we click [My] in the lower right corner; 2. Then in the My page, we need to click [Account] in the upper left corner; 3. Then come to the personal information page where we can bind mobile phones, WeChat, Alipay, and Taobao. Here we click [WeChat]; 4. After the final click, select the WeChat account that needs to be bound in the WeChat authorization page and click Just [Allow];

Table of Contents Astar Dapp Staking Principle Staking Revenue Dismantling of Potential Airdrop Projects: AlgemNeurolancheHealthreeAstar Degens DAOVeryLongSwap Staking Strategy & Operation "AstarDapp Staking" has been upgraded to the V3 version at the beginning of this year, and many adjustments have been made to the staking revenue rules. At present, the first staking cycle has ended, and the "voting" sub-cycle of the second staking cycle has just begun. To obtain the "extra reward" benefits, you need to grasp this critical stage (expected to last until June 26, with less than 5 days remaining). I will break down the Astar staking income in detail,
