欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JSP學(xué)習(xí)之?dāng)?shù)據(jù)庫開發(fā)小結(jié)

 更新時間:2015年09月15日 10:49:57   作者:逍遙  
這篇文章主要介紹了JSP學(xué)習(xí)之?dāng)?shù)據(jù)庫開發(fā),較為詳細(xì)的分析了JSP數(shù)據(jù)庫操作所涉及的數(shù)據(jù)類型、函數(shù)、模式及數(shù)據(jù)操作相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文總結(jié)了JSP學(xué)習(xí)之?dāng)?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è)定或更改數(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().....

標(biāo)量函數(shù):

算術(shù)函數(shù)(求絕對值,平方)
字符串函數(shù)(求字符串長度)
時間日期函數(shù)(返回系統(tǒng)當(dā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 '計算機(jī)');

數(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)絡(luò)數(shù)據(jù)庫的格式

jdbc:subprotocal://[hostname][:port][dbname][?parameter1=value1][&parameter2=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語句,應(yīng)使用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程序設(shè)計有所幫助。

相關(guān)文章

最新評論