JDBC连接各数据库 博客分类: javaSQL Server JDBCSQLSERVER2000mysqlclass
通过JDBC连接SQLSERVER2000数据库,方法如下:
1,首先加入以下三个jar包:msbase.jar、mssqlserver.jar、msutil.jar
2,配置如下:
<session-factory>
<!-- 是否显示SQL语句 -->
<property name="show_sql">true</property>
<!-- hibernate 连接SQLserice数据库:本地数据库 -->
<property name="hibernate.connection.url">jdbc:sqlserver://localhost;databaseName=test</property>
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.username">zhangsan</property>
<property name="hibernate.connection.password">123456789</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">3000</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
</session-factory>
JDBC连接mysql,配置如下:
<session-factory>
<!-- 是否显示SQL语句 -->
<property name="show_sql">true</property>
<!-- hibernate 连接SQLserice数据库:本地数据库 -->
<property name="hibernate.connection.url">jdbc:mysql://172.21.68.11:3306/test?characterEncoding=utf8</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">3000</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
</session-factory>