導航:首頁 > 編程大全 > 資料庫取數據

資料庫取數據

發布時間:2021-10-26 08:07:01

『壹』 SQL資料庫如何提取數據

1、查詢資料庫(test)中的所有表名的方法:

SELECT name
FROM [test]..sysobjects where xtype='U'
********
補充:
如果有的表不存在【時間】那就用下面的語句直接把含有【時間】列的表名找到:
SELECT d.name
FROM [test]..syscolumns a
inner join [test]..sysobjects d on a.id=d.id and d.xtype='U' and a.name='時間'
**********

2、遍歷這個表名取出數據插入到另外的資料庫中(SqlServer中的遍歷方法我不是很清楚,給你提供個思路,oracle的話我就能把程序寫出來了O(∩_∩)O~)。

如:遍歷結果存儲到資料庫test2中
insert into [test2]..遍歷出的表名 select * from 遍歷出的表名 where datediff(day,'2009-08-07',時間)>0;

重復上面的sql語句指導講資料庫test中的表名完全遍歷完為止。

*************************************************************
補充:我試驗了一下下面把實驗代碼給你(建一個存儲過程)
create proc test as
--定義游標變數
declare cur1 cursor for
SELECT d.name
FROM [test]..syscolumns a
inner join [test]..sysobjects d on a.id=d.id and d.xtype='U' and a.name='時間'
--定義臨時變數
declare @tmp varchar(1000)
--定義sql字元串
declare @strsql varchar(4000)
--打開游標
open cur1
--讀取第一條數據,也就是第一個表名
fetch next from cur1 into @tmp
--是讀完
while(@@fetch_status = 0)
begin
--連接sql文
set @strsql='insert into [test2]..'+@tmp++' select * from '+@tmp+' where datediff(day,'+char(39)+'2009-08-07'+char(39)+',時間)>0'
--執行這個sql
exec(@strsql)
--讀取下一條數據
fetch next from cur1 into @tmp
end
--關閉游標
close cur1
--摧毀游標所佔資源
deallocate cur1
*************************************************

---
以上,希望對你有所幫助。

『貳』 怎樣從HTML網頁中獲取SQL資料庫里的數據

1、sudo su postgres指令進入postgres。

『叄』 用sql語句怎麼從資料庫中提取結果

1、我們首先在創建一個WEB頁面,用EF導入資料庫中的一個實體模型,然後創建一個按鈕,點版擊按鈕以後用EF向數權據庫中執行insert操作。

『肆』 怎麼讀取資料庫中數據

1、導入.sql文件命令:mysql> USE 資料庫名;mysql> source d:/mysql.sql;
2、建立資料庫:mysql> CREATE DATABASE 庫名;
3、建立數據表:mysql> USE 庫名;mysql> CREATE TABLE 表名 (欄位名 VARCHAR(20), 欄位名 CHAR(1));
4、刪除資料庫:mysql> DROP DATABASE 庫名;
5、刪除數據表:mysql> DROP TABLE 表名;
6、將表中記錄清空:mysql> DELETE FROM 表名;
7、往表中插入記錄:mysql> INSERT INTO 表名 VALUES ("hyq","M");
8、更新表中數據:mysql-> UPDATE 表名 SET 欄位名1='a',欄位名2='b' WHERE 欄位名3='c';
9、用文本方式將數據裝入數據表中:mysql> load data local infile "d:/mysql.txt" into table 表名;

『伍』 請問如何從資料庫中讀取具體某個數據

從資料庫中來如何讀取數據呢源?
開發的時候(java或者c
)怎麼從資料庫中讀取java鏈接資料庫:
private
static
connection
getconnection(boolean
transaction)

『陸』 java怎麼把資料庫的數據取出來

Struts首先必須有一個struts-config.xml的配置文件

例:
<struts-config>
<data-sources />
<form-beans />
<global-exceptions />
<global-forwards />
<action-mappings >
<action path="/test" type="test.struts.TestAction" >
<forward name="success" path="/test.jsp"></forward>
</action>
</action-mappings>
</struts-config>

類:

public class TestActionextends Action {

public TestAction() {
}

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionForward forward;
//這里寫獲得資料庫中數據的代碼和其他地方一樣,可以網上查找
List dates=getDateInDatabases();
request.setAttribute("dates", dates);

forward=mapping.findForward("success");
return forward;



這時需要寫一張test.jsp
把拿到的數據隨便通過jsp的形式迭代出來即可

不知道明白沒有
----------------
jsp2.0可以用el表達式
不過。jsp的最上面必須加上這個

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>

<c:forEach items="${dates}" var="date" varStatus="true">
<tr>
<td>${date.**} </td>
<td>${date.**} </td>
</tr>

</c:forEach>

『柒』 怎樣從資料庫中讀出數據

public DataSet query(string sql)
{
DataSet ds = new DataSet();//DataSet是表的集合

SqlDataAdapter da = new SqlDataAdapter(sql, conn);//從資料庫中查詢

da.Fill(ds);//將數據填充到DataSet

connClose();//關閉連接內

return ds;//返回結果

}
這就讀出來了容

『捌』 系統怎麼從資料庫中取出數據

我覺得你要實現的這復個可能跟SpringMvc的關系不制是很大。 你要達到的目的其實就是在jvm啟動的時候把資料庫數據載入一份到內存,一個靜態變數和一個靜態初始化塊就可以搞定你的問題,這兩者都是在類載入的時候初始化一次,像前面回答的一樣,你可以用一個HashMap搞定。 稍微具體來說,一個靜態變數 public static final Map<key,value> cache=new HashMap<key,value>() static { cache=請求資料庫操作 } key你自己加,String還是int都行,value是你資料庫的結構,可以寫個實體。獲取的時候直接cache.get(key)就可以了。

『玖』 怎麼能把資料庫里的數據提取出來。

你直接把數據導出來不就行了啊...
SQL server可以把數據直接導成execl,.txt....格式的版本的啊內.
沒叫你全導出來啊,用SQL語句容,導出你要的就行了.
比如你只要哪個時間段的,你就加個時間限制啊.
樓主應該好好學學SQL,都可以的.

『拾』 如何從mysql資料庫讀取數據

讀取資料庫,首先要將資料庫的驅動包導入:如果是mysql資料庫,需要導入mysql-connector-java-5.1.27.jar,如果是oracle就需要導入oracle.jar包;
然後就是建立資料庫連接,使用Connection 新建連接,然後執行你的sql語句查詢出需要的數據,下面是兩個方法: public PageModel findAllUser(int pageNo,int pageSize){String sql = "select * from user where user_name <> 'root' order by user_name" +"limit" + (pageNo - 1) * pageSize + "," + pageSize;PageModel pageModel =null;Connection conn =null;Statement stmt =null;ResultSet rs = null;try{conn = DB.getConn();stmt = conn.createStatement();rs = stmt.executeQuery(sql);List user_List = new ArrayList();while(rs.next()){User user = new User();user.setUser_name(rs.getString("user_name"));user.setUser_password(rs.getString("user_password"));user.setUser_tel(rs.getString("user_tel"));user.setUser_email(rs.getString("user_email"));user.setUser_createDate(rs.getTimestamp("user_createdate"));user_List.add(user);}//取得所有記錄int totalRecords = getTotalRecords(conn);pageModel = new PageModel();pageModel.setPageSize(pageSize);pageModel.setList(user_List);pageModel.setTotalRecord(totalRecords);}catch(SQLException e){e.printStackTrace();}finally{DB.close(rs);DB.close(stmt);DB.close(conn);}return pageModel;} /** * 取得所有記錄 * @param conn * @return 所有記錄totalRecords */public int getTotalRecords(Connection conn){String sql = "select count(*) from user where user_name <> 'root' ";int totalRecords = 0;Statement stmt = null;ResultSet rs = null;try{conn = DB.getConn();stmt = conn.createStatement();rs = stmt.executeQuery(sql);if(rs.next()){totalRecords = rs.getInt(1);}}catch(SQLException e){e.printStackTrace();}finally{DB.close(rs);DB.close(stmt);DB.close(conn);}return totalRecords;}

閱讀全文

與資料庫取數據相關的資料

熱點內容
還有一個p開頭的網站 瀏覽:275
中央新下達文件50個省 瀏覽:613
銅仁網站製作多少錢 瀏覽:991
電影14路末班車免費觀看 瀏覽:665
ak愛看福利電影院 瀏覽:438
配置文件的工具 瀏覽:886
跨平台編程語言哪個好 瀏覽:316
win7桌面文件整理 瀏覽:757
如何進入電子網路發票應用系統 瀏覽:80
一部電影女主是蛇變的 瀏覽:779
恐怖片吻戲 瀏覽:62
有個小說主角叫楚天 瀏覽:884
大數據的內涵有哪些內容 瀏覽:800
日本大奶 電影 瀏覽:91
大數據反間 瀏覽:945
一個電影坐別人車後面有血 瀏覽:852
空姐大戰猛鬼電影 瀏覽:507
朴惠麗韓劇什麼電視 瀏覽:554
《柏林漂流》未刪減 瀏覽:804

友情鏈接