當前位置:首頁 » 操作系統 » 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了。

熱點內容
x3000r存儲卡 發布:2025-03-19 00:12:22 瀏覽:220
ie不顯示腳本錯誤 發布:2025-03-19 00:09:53 瀏覽:957
免費網頁源碼 發布:2025-03-19 00:09:00 瀏覽:261
工業企業資料庫 發布:2025-03-18 23:51:44 瀏覽:94
寶馬車的配置主要看哪些 發布:2025-03-18 23:50:09 瀏覽:484
esxi虛擬存儲 發布:2025-03-18 23:49:59 瀏覽:771
mc自己開伺服器地址 發布:2025-03-18 23:47:10 瀏覽:701
藍凌關聯配置什麼意思 發布:2025-03-18 23:46:16 瀏覽:347
雲存儲vmware 發布:2025-03-18 23:41:51 瀏覽:890
怎麼從配置模式轉到用戶模式 發布:2025-03-18 23:36:07 瀏覽:334