Oracle\DB2\Mysql常见使用区别

maven依赖

  • Oracle
<dependency>

<groupId>com.oracle</groupId>

<artifactId>ojdbc8</artifactId>

<version>12.2.0.1.0</version>

</dependency>
  • DB2
<dependency>

<groupId>com.ibm.db2.jcc</groupId>

<artifactId>db2jcc4</artifactId>

<version>10.1</version>

</dependency>
  • Mysql
<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>5.1.13</version>

</dependency>

驱动名称

  • Oracle
oracle.jdbc.driver.OracleDriver
  • DB2
com.ibm.db2.jcc.DB2Driver
  • Mysql
com.mysql.jdbc.Driver

连接url

  • Oracle
jdbc:oracle:thin:@//127.0.0.1:1521/XA
(XA是服务名,@后面的双斜杠可以不写)
  • DB2
 jdbc:db2://127.0.0.1:50000/<database_name>
  • Mysql
jdbc:mysql://127.0.0.1:3306/<database_name>
jdbc:mysql://127.0.0.1:3306/testDB?useUnicode=true&characterEncoding=utf8

分页语句

  • Oracle
select * from (
        select A.*,ROWNUM RN from (
                    select * from table_name
        ) A where ROWNUM <= page*pageSize
) B where RN > (page-1)*pageSize

page是第几页,pageSize是每页多少行;比如查询第8页,每页10行,结果是10条;
  • DB2
select * from(
	select b.*, rownumber() over() as rn from   (
		select * from table_name
	) as b
) as a where a.rn between startnum and endnum;

startnum是起始的位置号,endnum是结束位置号,比如between8,10查询第8位到第10位,结果是3条(8、9、10);
  • Mysql
select * from table_name limit startnum,pageSize

startnum是起始的位置号(不包含),pageSize是每页多少行,比如limit 2,3表示查询从第3位开始查3条(3、4、5);
展开阅读全文

没有更多推荐了,返回首页