Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added JDBC/bin/Demo/DEMO_EmpManage_JDBC.rar
Binary file not shown.
Binary file added JDBC/bin/JDBC_day01/demo/JDBCDemo01.class
Binary file not shown.
Binary file added JDBC/bin/JDBC_day01/demo/JDBCDemo02.class
Binary file not shown.
Binary file added JDBC/bin/JDBC_day01/demo/JDBCDemo03.class
Binary file not shown.
Binary file added JDBC/bin/JDBC_day01/demo/JDBCDemo04.class
Binary file not shown.
Binary file added JDBC/bin/JDBC_day01/lib/ojdbc5.jar
Binary file not shown.
Binary file added JDBC/bin/JDBC_day01/note/JDBC原理.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions JDBC/bin/JDBC_day01/note/summary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
JDBCDemo01��
1.��������
(1)�������ݿ�/����������(ע������):
1)Class.forName("oracle.jdbc.driver.OracleDriver");//����������(ע������)
��DriverManager.registerDriver(new OracleDriver());
2)Connection conn = DriverManager.getConnection(url, user, pwd);//�������Ӷ���
(2)Statement statement = conn.createStatement();//ͨ��Connection���󴴽�Statement����
(3)��ɾ��/��ѯ����Ҫ���Ρ�
(4)�ͷ���Դ
2.DML��ɾ��:int rows = statement.executeUpdate(sql);//Ӱ���˶�����//ִ��sql��䣨DML��,Ҫ���Ρ�
3.DQL��ѯ:
(1)ResultSet rs = statement.executeQuery(sql);//ִ��sql��䣨DQL������ȡ�����,Ҫ���Ρ�
(2)ResultSet��boolean next();
(3)getInt(),getString(),getDouble(),getDate(),getObject();//getInt(1),getInt(empno);//��ȡ��һ�У���ֱ��д������
4.�淶д��;

JDBCDemo02:
Java����ʵ���û���¼����֤�û���������.
��ʾSQLע�빥����
1.�������ݿ�
2.�����û��������뼰sql���ƴ��
3.ͨ��Connection���󴴽�Statement����
4.ִ��sql��䣨�����Dz�ѯ��
5.��ȡ�����������next()���������ж��û��Ƿ��½�ɹ���
6.�ͷ���Դ

JDBCDemo03:
ʹ��PrepareStatement��ʵ�����ݱ��IJ�ѯ������
PreparedStatement:Ԥ���루sql�Ƿ�Ϸ��淶������Statement�ӿڵ��ӽӿڣ���ֹSQL������������Ҫ���ܣ�����ߴ���Ŀɶ��ԣ���ά���ԣ����Ч�ʡ�
1.�������ݿ�
2.�����û��������뼰sql���ƴ��(�������ã�����ƴ��)//String sql = "select * from users where username=? and password=?";
3.����PrepareStatementԤ�������,��ΪPrepareStatement�ǽӿڣ���ʵ����ΪStatement����
1)ps = conn.prepareStatement(sql);//��Ԥ����sql.//����Connection�ӿڵķ���prepareStatement����ȡPrepareStatement�ӿڵ�ʵ���ࡣ
2)ps.setString(1, name);//����PrepareStatement����setXXX()���������ʺŸ�ֵ��1��2��ռλ��������ʾ�ڼ����ʺš�
4.���÷�����ִ��sql��䣬��ȡ�����
rs = ps.executeQuery();//��ΪprepareStatement�Ѿ�Ԥ�����sql������statement.executeQuery()����Ҫ��sql�����ˡ�
5.���������
6.�ͷ���Դ

JDBCDemo04:
ʹ��PrepareStatement��ʵ�����ݱ��ĸ��²�����
1.�������ݿ�
2.����Ҫ�޸ĵ��ñ�ź����û�����sql���ƴ��(�������ã�����ƴ��)
3.����PrepareStatementԤ�������,��ΪPrepareStatement�ǽӿڣ���ʵ����ΪStatement����
1)ps = conn.prepareStatement(sql);//��Ԥ����sql.//����Connection�ӿڵķ���prepareStatement����ȡPrepareStatement�ӿڵ�ʵ���ࡣ
2)ps.setString(1, name);//����PrepareStatement����setXXX()���������ʺŸ�ֵ��1��2��ռλ��������ʾ�ڼ����ʺš�
4.ִ��sql���
int rows = ps.executeUpdate();//��ΪprepareStatement�Ѿ�Ԥ�����sql������statement.executeUpdate()����Ҫ��sql�����ˡ�
5.�ͷ���Դ
Binary file added JDBC/bin/JDBC_day02/demo/JDBCDemo01.class
Binary file not shown.
Binary file added JDBC/bin/JDBC_day02/demo/JDBCDemo02.class
Binary file not shown.
Binary file added JDBC/bin/JDBC_day02/demo/JDBCDemo03.class
Binary file not shown.
Binary file added JDBC/bin/JDBC_day02/demo/bean/Users.class
Binary file not shown.
Binary file added JDBC/bin/JDBC_day02/demo/util/DBUtil.class
Binary file not shown.
62 changes: 62 additions & 0 deletions JDBC/bin/JDBC_day02/note/summary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
DBUtil:
实现JDBC的工具类
定义静态方法,直接返回数据库的连接对象
定义静态方法,关闭所有资源

JDBCDemo01:
使用了DBUtil工具类
使用PrepareStatement,实现模糊查询:ps.setString(1, "%"+condition+"%");

JDBCDemo02:
JDBC读取数据表users,每行数据封装到USers类的对象中。

JDBCDemo03:
银行转账
conn.setAutoCommit(false);//将事务的自动提交取消。
conn.commit();//手动提交事务,可将上面的逻辑全部控制在一个事务中。
conn.rollback();//回滚事务。

EmpManage_JDBC:
1.bean:实体类
2.dao:实现类(包)daoimpl,接口
3.test:测试类
4.DBUtil:
静态--连接数据库的方法
public static Connection getConnection (){
Connection conn = null;
try{
conn = Class.forName("jdbc.oracle.driver.OracleDriver");
String url = ?
String username = ?
String password = ?
conn = DriverManager.getConnection(url, username, password);
}catch(Exception e){
e.printStackTrace();
}
return conn;
};
静态--关闭资源的方法
public static void close(Connection conn,Statement ps,ResultSet rs) {
try {
if(rs != null) {
rs.close();
}
if(ps != null) {
ps.close();
}
if(conn != null) {
con.close();
}
}catch(SQLException e) {
e.printStackTrace();
}
}

补充:
1.sql.date转util.date可以自动转换。
util.date--->sql.date: java.sql.Date date = new java.sql.Date(emp.getHiredate().getTime());
//sql.Date的构造可以传1970的毫秒值,util.Date的getTime()可以得到1970的毫秒值。
2.String--->util.Date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
emp.setHiredate(sdf.parse(sc.next()));//将String--->util.date,会抛出ParseException异常。

49 changes: 49 additions & 0 deletions JDBC/bin/note/JDBC_day01/JDBC_day01_summary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
JDBCDemo01��
1.��������
(1)�������ݿ�/����������(ע������):
1)Class.forName("oracle.jdbc.driver.OracleDriver");//����������(ע������)
��DriverManager.registerDriver(new OracleDriver());
2)Connection conn = DriverManager.getConnection(url, user, pwd);//�������Ӷ���
(2)Statement statement = conn.createStatement();//ͨ��Connection���󴴽�Statement����
(3)��ɾ��/��ѯ����Ҫ���Ρ�
(4)�ͷ���Դ
2.DML��ɾ��:int rows = statement.executeUpdate(sql);//Ӱ���˶�����//ִ��sql��䣨DML��,Ҫ���Ρ�
3.DQL��ѯ:
(1)ResultSet rs = statement.executeQuery(sql);//ִ��sql��䣨DQL������ȡ�����,Ҫ���Ρ�
(2)ResultSet��boolean next();
(3)getInt(),getString(),getDouble(),getDate(),getObject();//getInt(1),getInt(empno);//��ȡ��һ�У���ֱ��д������
4.�淶д��;

JDBCDemo02:
Java����ʵ���û���¼����֤�û���������.
��ʾSQLע�빥����
1.�������ݿ�
2.�����û��������뼰sql���ƴ��
3.ͨ��Connection���󴴽�Statement����
4.ִ��sql��䣨�����Dz�ѯ��
5.��ȡ�����������next()���������ж��û��Ƿ��½�ɹ���
6.�ͷ���Դ

JDBCDemo03:
ʹ��PrepareStatement��ʵ�����ݱ��IJ�ѯ������
PreparedStatement:Ԥ���루sql�Ƿ�Ϸ��淶������Statement�ӿڵ��ӽӿڣ���ֹSQL������������Ҫ���ܣ�����ߴ���Ŀɶ��ԣ���ά���ԣ����Ч�ʡ�
1.�������ݿ�
2.�����û��������뼰sql���ƴ��(�������ã�����ƴ��)//String sql = "select * from users where username=? and password=?";
3.����PrepareStatementԤ�������,��ΪPrepareStatement�ǽӿڣ���ʵ����ΪStatement����
1)ps = conn.prepareStatement(sql);//��Ԥ����sql.//����Connection�ӿڵķ���prepareStatement����ȡPrepareStatement�ӿڵ�ʵ���ࡣ
2)ps.setString(1, name);//����PrepareStatement����setXXX()���������ʺŸ�ֵ��1��2��ռλ��������ʾ�ڼ����ʺš�
4.���÷�����ִ��sql��䣬��ȡ�����
rs = ps.executeQuery();//��ΪprepareStatement�Ѿ�Ԥ�����sql������statement.executeQuery()����Ҫ��sql�����ˡ�
5.���������
6.�ͷ���Դ

JDBCDemo04:
ʹ��PrepareStatement��ʵ�����ݱ��ĸ��²�����
1.�������ݿ�
2.����Ҫ�޸ĵ��ñ�ź����û�����sql���ƴ��(�������ã�����ƴ��)
3.����PrepareStatementԤ�������,��ΪPrepareStatement�ǽӿڣ���ʵ����ΪStatement����
1)ps = conn.prepareStatement(sql);//��Ԥ����sql.//����Connection�ӿڵķ���prepareStatement����ȡPrepareStatement�ӿڵ�ʵ���ࡣ
2)ps.setString(1, name);//����PrepareStatement����setXXX()���������ʺŸ�ֵ��1��2��ռλ��������ʾ�ڼ����ʺš�
4.ִ��sql���
int rows = ps.executeUpdate();//��ΪprepareStatement�Ѿ�Ԥ�����sql������statement.executeUpdate()����Ҫ��sql�����ˡ�
5.�ͷ���Դ
Binary file added JDBC/bin/note/JDBC_day01/JDBC原理.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions JDBC/bin/note/JDBC_day02/JDBC_day02_summary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
DBUtil:
实现JDBC的工具类
定义静态方法,直接返回数据库的连接对象
定义静态方法,关闭所有资源

JDBCDemo01:
使用了DBUtil工具类
使用PrepareStatement,实现模糊查询:ps.setString(1, "%"+condition+"%");

JDBCDemo02:
JDBC读取数据表users,每行数据封装到USers类的对象中。

JDBCDemo03:
银行转账
conn.setAutoCommit(false);//将事务的自动提交取消。
conn.commit();//手动提交事务,可将上面的逻辑全部控制在一个事务中。
conn.rollback();//回滚事务。
43 changes: 43 additions & 0 deletions JDBC/bin/note/project/one/project_EmpManage_summary
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
EmpManage_JDBC��
1.bean:ʵ����
2.dao:ʵ����(��)daoimpl���ӿ�
3.test:������
4.DBUtil:
��̬--�������ݿ�ķ���
public static Connection getConnection (){
Connection conn = null;
try{
conn = Class.forName("jdbc.oracle.driver.OracleDriver");
String url = ��
String username = ��
String password = ��
conn = DriverManager.getConnection(url, username, password);
}catch(Exception e){
e.printStackTrace();
}
return conn;
};
��̬--�ر���Դ�ķ���
public static void close(Connection conn,Statement ps,ResultSet rs) {
try {
if(rs != null) {
rs.close();
}
if(ps != null) {
ps.close();
}
if(conn != null) {
con.close();
}
}catch(SQLException e) {
e.printStackTrace();
}
}

���䣺
1.sql.dateתutil.date�����Զ�ת����
util.date--->sql.date�� java.sql.Date date = new java.sql.Date(emp.getHiredate().getTime());
//sql.Date�Ĺ�����Դ�1970�ĺ���ֵ��util.Date��getTime()���Եõ�1970�ĺ���ֵ��
2.String--->util.Date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
emp.setHiredate(sdf.parse(sc.next()));//��String--->util.date,���׳�ParseException�쳣��
Binary file not shown.
52 changes: 52 additions & 0 deletions JDBC/bin/note/project/two/carRent_JDBC.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
--����
create table car(
brand varchar2(10) not null,
vehicleId varchar2(20) not null unique,
perRent number(4) not null,
type varchar2(20) not null
);
create table bus(
brand varchar2(10) not null,
vehicleId varchar2(20) not null unique,
perRent number(4) not null,
seat number(2) not null
);
create table truck(
brand varchar2(10) not null,
vehicleId varchar2(20) not null unique,
perRent number(4) not null,
tonnage number(2) not null
);
create table rented(
brand varchar2(10) not null,
vehicleId varchar2(20) not null unique,
perRent number(4) not null,
type varchar2(20),
seat number(2),
tonnage number(2)
);
--��������
insert into car values('����','��NY28588',800,'X6');
insert into car values('����','��CNY3284',600,'550i');
insert into car values('���','��NT37465',300,'������');
insert into car values('���','��NT96968',600,'GL8');
insert into bus values('��','��6566754',800,16);
insert into bus values('����','��8696997',800,16);
insert into bus values('��','��9696996',1500,34);
insert into bus values('����','��8696998',1500,34);
insert into truck values('һ�����','��MH98725',50,5);
insert into truck values('�������','��L593216',50,5);
insert into truck values('һ�����','��NU98631',50,10);
insert into truck values('�������','��CY56312',50,10);
--�鿴��
select * from car;
select * from bus;
select * from truck;
select * from rented;
--ɾ����
drop table car;
drop table bus;
drop table truck;
drop table rented;


Loading