當前位置:首頁 » 操作系統 » struts連接資料庫

struts連接資料庫

發布時間: 2023-07-08 22:33:02

⑴ struts2 中 連接資料庫報錯 ,是一個簡單的登陸界面,頁面上沒有報錯的情況,只是在登陸時,500的錯誤

public class ManagerLogin extends ActionSupport{

private Student student=null;
這兒出錯,你給student賦了null
當你在後面的excute方法中取得的student就是null
所以在ResultSet sqlSelect=Dbconnect.executeQuery("select stuName,password from student where stuName='"+student.getStuName()+"'and password='"+student.getPassword()+"'");
此處會報空指針異常錯誤。

⑵ Struts2中怎樣連接資料庫

struts2框架就是MVC模式(模型、視圖、控制器)中的控制器
如果只使用了框架struts2 ,那麼鏈接資料庫就是通過jdbc鏈接

如果在struts2框架的基礎上同時使用了hibernate,這樣鏈接資料庫就是hibernate的事了。

⑶ struts2 資料庫連接問題!~

package com.common;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {
//創建連接
public static Connection getConnection() {
Connection DBconn = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://localhost:1433;databasename=Dept";
String user = "sa";
String password = "123";
DBconn = DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException e1) {
System.out.println("驅動程序載入錯誤");
} catch (SQLException e2) {
System.out.println("資料庫連接時錯誤");
} catch (Exception e3) {
e3.printStackTrace();
}
return DBconn;
}

//關門連接
public static void clear(Connection DBconn) {
if (DBconn != null) {
try {
DBconn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}

熱點內容
訪問ip量伺服器 發布:2025-10-18 19:49:48 瀏覽:873
C語言輸入怎麼寫 發布:2025-10-18 19:27:46 瀏覽:746
如何修改安卓手機屏幕解析度 發布:2025-10-18 19:08:46 瀏覽:366
老式監控主機如何更改密碼 發布:2025-10-18 18:49:59 瀏覽:578
android切換app 發布:2025-10-18 18:43:50 瀏覽:903
百度雲上傳超大文件 發布:2025-10-18 18:43:08 瀏覽:43
樂視1怎麼取消密碼是多少 發布:2025-10-18 18:26:16 瀏覽:39
逆鱗壓縮 發布:2025-10-18 18:15:57 瀏覽:768
數據存儲器ds216 發布:2025-10-18 18:03:55 瀏覽:983
手機游戲安卓源碼 發布:2025-10-18 18:02:05 瀏覽:863