为什么需要Java语言来 *** 作数据库的增删改查

为什么需要Java语言来 *** 作数据库的增删改查,第1张

import javasql;

/课题:封装数据库的增删改查的工具类的实现。

假设相关数据库的表结构如下:

表名:user

列名及属性:id(int 自增),name(varchar(20)),tele(char(12)),birthday(date)

@author shy2850

/

public class UserDAO {

Connection conn;

public UserDAO(Connection conn) {

thisconn = conn;

}

public int save(User user) throws SQLException {

String sql = "insert into user values(0,,,)";

PreparedStatement pstmt = connprepareStatement(sql);

pstmtsetString(1, usergetName());

pstmtsetString(2, usergetTele());

pstmtsetDate(3, usergetBirthday());

int n = pstmtexecuteUpdate();

pstmtclose();

return n;

}

public int delete(User user) throws SQLException{

String sql = "delete from user where id = "+usergetId();

Statement stmt = conncreateStatement();

int n = stmtexecuteUpdate(sql);

stmtclose();

return n;

}

public int update(User user) throws SQLException{

String sql = "update user set name=, tele=, birthday= where id = "+usergetId();

PreparedStatement pstmt = connprepareStatement(sql);

pstmtsetString(2, usergetName());

pstmtsetString(3, usergetTele());

pstmtsetDate(4, usergetBirthday());

int n = pstmtexecuteUpdate(sql);

pstmtclose();

return n;

}

public User getUser(Integer id) throws SQLException{

String sql = "select from user where id = " + id;

Statement stmt = conncreateStatement();

ResultSet rs = stmtexecuteQuery(sql);

User user = getUserFromResultSet(rs);

rsclose();

stmtclose();

return user;

}

static User getUserFromResultSet(ResultSet rs) throws SQLException{

Integer id = rsgetInt("id");

String name= rsgetString("name");

String tele= rsgetString("tele");

Date birthday = rsgetDate("birthday");

return new User(id, name, tele, birthday);

}

}

/

构建数据库表的java类映射

/

class User{

private Integer id;

private String name;

private String tele;

private Date birthday;

public User() {

}

public User(Integer id, String name, String tele, Date birthday) {

super();

thisid = id;

thisname = name;

thistele = tele;

thisbirthday = birthday;

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

thisid = id;

}

public String getName() {

return name;

}

public void setName(String name) {

thisname = name;

}

public String getTele() {

return tele;

}

public void setTele(String tele) {

thistele = tele;

}

public Date getBirthday() {

return birthday;

}

public void setBirthday(Date birthday) {

thisbirthday = birthday;

}

}

php是编程语言,也是

脚本语言

,二者不冲突

能否调用数据库与编程语言无关,只要提供了调用的接口,无论什么语言都可以调用

Javascript

也可调用mysql的(通过nodejs),php也是通过mysql扩展调用数据库

因为方便,比如:

系统新版本上线,那么可能对数据库中某些表增加了列,有些表插入了新配置数据,建立某些新表等等等,难道通过IDE界面一个个弄么?实现准备好脚本,直接运行就好了啊。而且有的时候,如果有多个数据中心,多个数据库呢,难道同样的 *** 作都在IDE上一遍遍的做?又慢又容易出纰漏啊。

而且比如你有一套维护动作,比如是维护了某些表上面的索引,那么换个DB,只需要改些脚本里面的名字变量之类的就好喽,可以复用啊。

1970年,美国IBM研究中心的EFCodd连续发表多篇论文,提出关系模型。1972年,IBM公司开始研制实验型关系数据库管理系统SYSTEM R,为其配制的查询语言称为SQUARE(Specifying Queries As Relational Expression)语言,在该语言中使用了较多的数学符号。1974年,Boyce和Chamberlin把SQUARE修改为SEQUEL(Structured English QUEry Language)语言。这两个语言在本质上是相同的,但后者去掉了数学符号,采用英语单词表示和结构式的语法规则,看起来很像英语句子,用户比较欢迎这种形式的语言。后来SEQUEL简称为SQL(Structured Query Language)语言,即“结构化查询语言”。

在认识到关系模型的诸多优越性后,许多厂商纷纷研制关系数据库管理系统(例如:Oracle、DB2、Sybase等),这些数据库管理系统的 *** 纵语言也以SQL参照。1986年10月美国国家标准化协会(ANSI)发布了X3135-1986《数据库语言SQL》,1987年6月国际标准化组织(ISO)采纳其为国际标准。我们称其为“SQL-86”标准。1989年10月,ANSI又颁布了增强完整性特征的“SQL-89”标准。随后,ISO对该标准进行了大量的修改和扩充,在1992年8月发布了标准化文件“ISO/IEC 9075:1992《数据库语言SQL》”,我们称其为SQL92或SQL2标准。1999年ISO又颁布了“ISO/IEC 9075:1999《数据库语言SQL》”标准化文件,我们称其为SQL99或SQL3标准。

以上就是关于为什么需要Java语言来 *** 作数据库的增删改查全部的内容,包括:为什么需要Java语言来 *** 作数据库的增删改查、php又不是编程语言,为什么可以调用mysql数据库、sql server 有可视化 *** 作为什么还要用数据库语言来建表和约束等 *** 作等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/10200874.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-06
下一篇 2023-05-06

发表评论

登录后才能评论

评论列表(0条)

保存