當前位置:首頁 » 操作系統 » jsp修改資料庫

jsp修改資料庫

發布時間: 2023-07-03 22:47:50

❶ JSP中如何對資料庫中的數據進行刪除增加等操作

問題太抽象,/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/package ******;
import java.io.PrintWriter;
import java.sql.*;/**
* @author wfg
*/
public class DB_Conn {
private String driverName = "com.mysql.jdbc.Driver"; //JDBC驅動
private String userName = "root"; //資料庫用戶名
private String userPwd = "*****"; //資料庫用戶密碼
private String dbName = "******"; //資料庫名
private String url = "jdbc:mysql://localhost:3306/"+dbName+"?user="+userName+
"&password="+userPwd; //資料庫連接字元串
private Connection conn = null; //資料庫連接對象
public Statement sm = null; //資料庫語句對象
private PrintWriter out = null; //建立資料庫連接函數
public void ConnectDB(){
try{
Class.forName(driverName).newInstance();
conn = DriverManager.getConnection(url);
sm = conn.createStatement();
}
catch(Exception e){
e.printStackTrace();
out.print("資料庫連接失敗!");
}
} //釋放資料庫連接函數
public void CloseDB(){
try{
if(sm != null){
sm.close();
}
conn.close();
}
catch(SQLException SqlE){
SqlE.printStackTrace();
out.print("資料庫關閉失敗!");
}
}
}
這是先建立連接

❷ jsp修改怎樣修改mysql資料庫中的數據句

知道有一種形式:
之前得封裝下2個文件,頁面引用:
<%@
taglib
uri="/WEB-INF/database.tld"
prefix="database"%>
<%@
taglib
uri="/WEB-INF/beans.tld"
prefix="beans"%>
添加或刪除sql

❸ 如何用一張JSP頁面連接資料庫,實現查詢,修改操作

1.通過jdbc連接上資料庫,並從中獲取一個連接。(建議由一個工具類提供)
2.創建一個jsp頁面、一個servlet類和一個service業務邏輯類。
3.當點擊查詢按鈕時調用servlet並把文本框中的參數傳遞過去。
4.在servlet中獲取頁面傳遞過來的參數,並調用service中方法(此方法負責條件查詢並返回list集合)
5.servlet中把查詢集合放到request作用域並轉發到jsp頁面進行迭代,把數據取出展示即可。

❹ 如何在jsp頁面內獲取資料庫內容,且通過按鈕修改資料庫內容

從資料庫中讀取ID,並用<input type="hidden" value='<%=id%>'/>,放到<form></form>里。提交的時候,就可以獲取id了。

熱點內容
安卓版微信收藏在哪裡 發布:2025-03-18 23:09:11 瀏覽:155
h5與資料庫連接 發布:2025-03-18 23:07:40 瀏覽:23
c語言編輯是 發布:2025-03-18 23:06:25 瀏覽:982
gamemaker腳本 發布:2025-03-18 23:01:12 瀏覽:358
怎樣給qq文件加密 發布:2025-03-18 22:59:18 瀏覽:613
為什麼qq密碼對卻登錄上 發布:2025-03-18 22:57:54 瀏覽:90
盤錦電腦伺服器 發布:2025-03-18 22:57:51 瀏覽:676
波蘭達演算法 發布:2025-03-18 22:57:10 瀏覽:328
怎麼連接動車上的wifi密碼多少 發布:2025-03-18 22:49:34 瀏覽:531
密碼放在什麼文件夾裡面 發布:2025-03-18 22:48:12 瀏覽:316