当前位置: 移动技术网 > IT编程>开发语言>Java > JSP学习之数据库开发小结

JSP学习之数据库开发小结

2017年12月12日  | 移动技术网IT编程  | 我要评论

婴儿误吞电池,叔控学园汉化组,中国锑矿网

本文总结了jsp学习之数据库开发方法。分享给大家供大家参考。具体如下:

sql语言的组成:

1>数据定义语言ddl 用于定义sql模式,数据表,视图和索引等数据库对象
2>数据操纵语言dml 数据查询和数据更新语言
3>数据控制语言dcl 设定或更改数据库用户或角色
4>嵌入式sql语言 sql语句嵌入到宿主语言中

数据类型:

1>数字类型 integer smallint real numeric decimal float double...
2>日期和时间类型 timestamp date time...
3>字符和字符串类型 character char varchar...

聚合函数:avg(),count(),max(),min(),sum().....

标量函数:

算术函数(求绝对值,平方)
字符串函数(求字符串长度)
时间日期函数(返回系统当前时间)
中继数据函数

模式:

数据库表的集合称为一个模式,由模式名和模式的拥有者组成

create schema student authorization stu;
drop schema student cascade;
cascade一起删除模式内的数据库对象
restrict模式内存在数据库对象时不允许删除

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 '计算机');

数据表的创建修改和删除

alter table student add address char(30);添加address列
drop table student cascade|restrict

索引的创建和删除

create index xuehao_index on student(xuehao)
drop index xuehao_index

数据修改update student set age=age+1 where xuehao='2004007'

数据删除delete from student;

jdbc编程

jdbc:subprotocal:data source identifier
jdbc:odbc:university 以jdbc odbc桥的方式连接university数据库
jdbc:odbc:university?user=username&password=password 带有参数的连接

连接网络数据库的格式

jdbc:subprotocal://[hostname][:port][dbname][?parameter1=value1][¶meter2=value2]......
jdbc:microsoft:sqlserver://localhost:1433;database=university?user=username&password=password

使用jdbc驱动来连接sqlserver数据库:

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对象主要是用来执行sql语句,可以利用connection对象的createstatement()方法创建一个statement对象

statement statement=conn.createstatement();
string sql="select * from student";
resultset rs=statement.executequery(sql);

resultset接受返回结果
如果要执行insert,delete,update,create,drop语句,应使用executeupdate方法

string sql="delete from student where xuehao="+"'0741210'";
int i=statement.executeupdate(sql);//返回值是受影响的行数
system.out.println(i);
public boolean execute()throws exception

用于执行事先不知道类型的sql语句,用于动态处理未知的sql语句

希望本文所述对大家的jsp程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网