當前位置:首頁 » 操作系統 » struts2資料庫

struts2資料庫

發布時間: 2023-01-30 23:35:35

㈠ Struts2 如何實現Excel導入資料庫

創建資料庫
選擇
開始菜單
中→程序→【Management
sql
Server
2008】→【SQL
Server
Management
Studio】命令,打開【SQL
Server
Management
Studio】窗口,並使用Windows或
SQL
Server
身份驗證
建立連接。
在【對象
資源管理器
】窗口中展開伺服器,然後選擇【資料庫】節點
右鍵單擊【資料庫】節點,從彈出來的
快捷菜單
中選擇【新建資料庫】命令。
執行上述操作後,會彈出【新建資料庫】對話框。在對話框、左側有3個選項,分別是【常規】、【選項】和【
文件組
】。完成這三個選項中的設置會後,就完成了資料庫的創建工作,
在【資料庫名稱】
文本框
中輸入要新建資料庫的名稱。例如,這里以「新建的資料庫」。
在【所有者】文本框中輸入新建資料庫的所有者,如sa。根據資料庫的使用情況,選擇啟用或者禁用【使用
全文索引

復選框

在【
資料庫文件
】列表中包括兩行,一行是資料庫文件,而另一行是日記文件。通過單擊下面的【添加】、【刪除】按鈕添加或刪除資料庫文件。
切換到【選項頁】、在這里可以設置資料庫的排序規則、恢復模式、兼容級別和其他屬性。
切換到【文件組】頁,在這里可以添加或
刪除文件
組。
完成以上操作後,單擊【確定】按鈕關閉【新建資料庫】對話框。至此「新建的數據」資料庫創建成功。新建的資料庫可以再【對象資源管理器】窗口看到。

javaweb開發 struts2關於資料庫連接的問題

你給的信息也不夠啊。下下來的東西,這個項目加到tomcat裡面了?
500的狀態碼說明內部伺服器錯誤。
這種東西自己寫也很簡單。
基於Struts2的使用JDBC 連接資料庫就行了。
使用mysql資料庫,然後下一個這個資料庫的管理軟體

㈢ 在struts2中對資料庫的增刪改查語句!

struts2是一個web層的框架,對資料庫的增刪改查沒有影響,它只負責跟web頁面打交道,接收、傳遞數據、跳轉到相應顯示頁面。而實現對數據的增刪改查,如果你用沒有用orm框架而直接用jdbc,則寫相應的sql語句,然後執行即可,例如增加一條數據:
public int userAdd(User user){
int rt = 0 ;
String sql = "insert into USERS(userName,password,realName,sex) values(?,?,?,?)" ;
try{
conn = this.getConn() ;
pstmt = conn.prepareStatement(sql) ;
pstmt.setString(1, user.getUserName()) ;
pstmt.setString(2, user.getPassWord()) ;
pstmt.setString(3, user.getRealName()) ;
pstmt.setString(4, user.getSex()) ;
rt = pstmt.executeUpdate() ;
}catch(SQLException e){
e.printStackTrace() ;
}catch(Exception e){
e.printStackTrace() ;
}finally{
this.closeAll(conn, pstmt, rs) ;
}
return rt ;
}
倘若你用了hibernate等orm框架,則相對簡單,不用那麼費勁的進行一個一個的賦值了,它對jdbc進行了封裝,並且本身還有一種hql語言。說到底都是用sql語句進行資料庫操作!具體請查找資料!

㈣ Struts2中怎樣連接資料庫

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

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

㈤ struts2怎樣上傳文件到資料庫中

struts2怎樣上傳文件到資料庫中
struts2上傳文件保存到資料庫中,參考代碼如下:
File file=new File("D:/2.jpg");
try {
FileInputStream in=new FileInputStream(file);
int len=0;
byte[] b=new byte[(int) file.length()];
in.read(b);
in.close();
System.out.println(b.length);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

㈥ 怎樣將struts2上傳文件保存到資料庫中

1在你的struts-config中首先不能使用form,使用的話會報錯
2在你jsp的form中增加屬性enctype="multipart/form-data"
這樣你的文件內容會被都城二進制數據傳到後台,在後台獲取值保存及可以了

㈦ struts2中action裡面怎麼寫一個方法直接查詢資料庫數據,

先寫的DAO:public List<FileModel> findAll()
{
Connection con = null ;
PreparedStatement ps = null ;
FileModel file = null ;
ResultSet rs = null;
List<FileModel> set = null ;
try
{
con = DBconnection.getConnection();
String sql = "select * from file ;
ps = con.prepareStatement(sql);

set = new LinkedList<FileModel>();
rs = ps.executeQuery() ;

while(rs.next())
{
file = new FileModel();
file.setFilepath(rs.getString(1));
file.setFiletime(rs.getTimestamp(2));
file.setFileintroce(rs.getString(3));
file.setFilediscuss(rs.getString(4));
file.setFilescore(rs.getFloat(5));
file.setFiletype(rs.getString(6));
file.setDirection(rs.getString(7));
file.setFileid(rs.getInt(8));
file.setFilename(rs.getString(9));
set.add(file);
}

}
catch(SQLException e)
{
throw new RuntimeException(e.getMessage(),e);
}
finally
{
DBconnection.free(rs, ps, con);
}

return set;
}
在action中調用DAO:
public class FindAction extends ActionSupport {
private Dao = new Dao();

@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
LinkedList<FileModel> modelSet = (LinkedList<FileModel>) .findAll();

if (modelSet!=null){
System.out.println(modelSet);

ActionContext.getContext().getSession().put("msg", modelSet);
return SUCCESS;}
else
return ERROR;
}
}

㈧ 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();
}
}
}
}

㈨ struts2資料庫動態國際化

國際化一般是用資源文件的。根據當前你選定的語言環境,決定讀取哪個資源文件。
例如你有2個資源文件如下:
myi18n_zh.properties
myi18n_en.properties
在你的登陸頁面,如果用戶選擇了簡體中文,則
request.getSession.setAttribute("local","zh");
如果選擇English,則
request.getSession.setAttribute("local","en");

JSP頁面中,使用自定義標簽來讀取資源文件內容(其實struts2自己也有個標簽,叫做:<s:text value=""/>,我一般自定義,這樣就不依賴於struts2了),在你自定義標簽的對應的類裡面,獲取當前local的值:
String local = this.pageContext.getSession.getAttribute("local");
來決定讀取哪個資源文件,再按照key值取出value,寫到頁面上,這樣就實現國際化了

熱點內容
在jsp中使用資料庫 發布:2024-03-29 19:29:01 瀏覽:786
dns伺服器江川區ip地址 發布:2024-03-29 18:47:53 瀏覽:328
sql統計百分比 發布:2024-03-29 18:47:14 瀏覽:692
javatoolsfor 發布:2024-03-29 18:17:55 瀏覽:900
linuxi2c驅動 發布:2024-03-29 18:09:56 瀏覽:672
junit源碼下載 發布:2024-03-29 18:00:10 瀏覽:526
本田雅閣壓縮機不工作 發布:2024-03-29 17:59:13 瀏覽:601
溯源碼可以偽造嗎 發布:2024-03-29 17:54:45 瀏覽:57
北京編程傳 發布:2024-03-29 17:54:44 瀏覽:436
編程畫曲線 發布:2024-03-29 17:48:59 瀏覽:60