JSP學習之數(shù)據(jù)庫開發(fā)小結(jié)
本文總結(jié)了JSP學習之數(shù)據(jù)庫開發(fā)方法。分享給大家供大家參考。具體如下:
SQL語言的組成:
1>數(shù)據(jù)定義語言DDL 用于定義SQL模式,數(shù)據(jù)表,視圖和索引等數(shù)據(jù)庫對象
2>數(shù)據(jù)操縱語言DML 數(shù)據(jù)查詢和數(shù)據(jù)更新語言
3>數(shù)據(jù)控制語言DCL 設定或更改數(shù)據(jù)庫用戶或角色
4>嵌入式SQL語言 SQL語句嵌入到宿主語言中
數(shù)據(jù)類型:
1>數(shù)字類型 INTEGER SMALLINT REAL NUMERIC DECIMAL FLOAT DOUBLE...
2>日期和時間類型 TIMESTAMP DATE TIME...
3>字符和字符串類型 CHARACTER CHAR VARCHAR...
聚合函數(shù):AVG(),COUNT(),MAX(),MIN(),SUM().....
標量函數(shù):
算術(shù)函數(shù)(求絕對值,平方)
字符串函數(shù)(求字符串長度)
時間日期函數(shù)(返回系統(tǒng)當前時間)
中繼數(shù)據(jù)函數(shù)
模式:
數(shù)據(jù)庫表的集合稱為一個模式,由模式名和模式的擁有者組成
CREATE SCHEMA student AUTHORIZATION stu;
DROP SCHEMA student CASCADE;
CASCADE一起刪除模式內(nèi)的數(shù)據(jù)庫對象
RESTRICT模式內(nèi)存在數(shù)據(jù)庫對象時不允許刪除
CREATE TABLE student( xuehao CHAR(7) PRIMARY KEY, name CHAR(8) NOT NULL, sex CHAR(2), age SMALLINT, jiguan CHAR(20), dept CHAR(10) DEFAULT '計算機');
數(shù)據(jù)表的創(chuàng)建修改和刪除
ALTER TABLE student ADD address CHAR(30);添加address列
DROP TABLE student CASCADE|RESTRICT
索引的創(chuàng)建和刪除
CREATE INDEX xuehao_index ON student(xuehao)
DROP INDEX xuehao_index
數(shù)據(jù)修改UPDATE student SET age=age+1 WHERE xuehao='2004007'
數(shù)據(jù)刪除DELETE FROM student;
JDBC編程
jdbc:subprotocal:data source identifier
jdbc:odbc:university 以jdbc odbc橋的方式連接university數(shù)據(jù)庫
jdbc:odbc:university?user=username&password=password 帶有參數(shù)的連接
連接網(wǎng)絡數(shù)據(jù)庫的格式
jdbc:subprotocal://[hostname][:port][dbname][?parameter1=value1][¶meter2=value2]......
jdbc:microsoft:sqlserver://localhost:1433;dataBase=university?user=username&password=password
使用JDBC驅(qū)動來連接sqlserver數(shù)據(jù)庫:
Try{ forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=university" conn=DriverManager.getConnection(url,userName,password); catch(Exception e){ System.out.println(e); }
使用JDBC-ODBC橋來連接:
Try{ forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); url="jdbc:odbc:university" conn=DriverManager.getConnection(url,userName,password); catch(Exception e){ System.out.println(e); }
Statement對象主要是用來執(zhí)行SQL語句,可以利用Connection對象的createStatement()方法創(chuàng)建一個Statement對象
Statement statement=conn.createStatement(); String sql="select * from student"; ResultSet rs=statement.executeQuery(sql);
ResultSet接受返回結(jié)果
如果要執(zhí)行insert,delete,update,create,drop語句,應使用executeUpdate方法
String sql="delete from student where xuehao="+"'0741210'"; int i=statement.executeUpdate(sql);//返回值是受影響的行數(shù) System.out.println(i); public boolean execute()throws Exception
用于執(zhí)行事先不知道類型的SQL語句,用于動態(tài)處理未知的SQL語句
希望本文所述對大家的JSP程序設計有所幫助。
- jsp簡單連接SQL Server2000數(shù)據(jù)庫的方法
- JSP如何連接DB2數(shù)據(jù)庫
- JSP連接Access數(shù)據(jù)庫
- 加快JDBC設計中JSP訪問數(shù)據(jù)庫
- 在JSP中訪問MS SQL Server數(shù)據(jù)庫
- 純JSP+DWR實現(xiàn)三級聯(lián)動下拉選擇菜單實現(xiàn)技巧
- jsp中將后臺傳遞過來的json格式的list數(shù)據(jù)綁定到下拉菜單select
- jsp+javascript打造級連菜單的實例代碼
- jsp從數(shù)據(jù)庫獲取數(shù)據(jù)填充下拉框?qū)崿F(xiàn)二級聯(lián)動菜單的方法
相關(guān)文章
Spring MVC自定義日期類型轉(zhuǎn)換器實例詳解
這篇文章主要介紹了Spring MVC自定義日期類型轉(zhuǎn)換器實例詳解的相關(guān)資料,需要的朋友可以參考下2017-04-04jsp中利用jquery+ajax在前后臺之間傳遞json格式參數(shù)
前后臺之間的參數(shù)傳遞一直是個問題,經(jīng)過一段時間的實驗琢磨,終于搞定,先把經(jīng)驗拿出來與大家分享,希望可以讓新手朋友們少走彎路2013-10-10