With the second Beanfactory method: 1. Download the latest version of MSSQL's latest driver and copy this drive to Tomcat's lib!! This step is very important and cost me two days to check the reason. If you don't copy, you'll have to wait for the newspaper to find the resources. 2. Adding a configuration file to a Web project 3. Note the writing of the driver class name,< msql2005 before: (Really, this is too CNM, it is a very disturbing thing)
Com.microsoft.jdbc. SQL Server. SQLServerDriverAfter the >=2005 version
Com.microsoft.sqlserver.jdbc.SQLServerDriver.
4. Add another sessionfactory bean to the Spring-hibernate.xml
============ The following are network references ========================= tomcat6.0 configuration database connection pool missing Msbase.jar,mssqlserver.jar,msutil.jar and adding files under Tomcat Lib and Webroot\web-inf\lib DBCP Connection Pool package, to be web-inf/lib under the same directory
The driverclassname of the SQL Server2000 JDBC driver is "com.microsoft.jdbc.sqlserver.SQLServerDriver"
The driverclassname of the SQL Server2005 JDBC driver is "com.microsoft.sqlserver.jdbc.SQLServerDriver"
Tomcat *\conf\context.xml configuration <resource name= "Jdbc/pubs" auth= "Container" type= "Javax.sql.DataSource" maxactive= " "Maxldle=" 30 " Maxwait= "10000" username= "sa" password= "sa" driverclassname= "com.microsoft.jdbc.sqlserver.SQLServerDriver" Url= "Jdbc:microsoft:sqlserver://localhost:1433;tabasename=webshop" factory= "Org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"/> <resourcelink global= "jdbc/pubs" name= "Jdbc/pubs" type= "Javax.sql.DataSource"/> and config <resource-ref in Web. xml > <description>DataSource</description> <res-ref-name>jdbc/pubs</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>applicationcontext.xml setting <bean id= "DataSource" class= " Org.springframework.jndi.JndiObjectFactoryBean "> <property name= "Jndiname" value= "Java:/comp/env/jdbc/pubs"/> </bean> |
Reprint: http://corrinejtt.javaeye.com/blog/608248 Various configurations Oracle Connection Configuration Hibernate.dialect = Org.hibernate.dialect.OracleDialect
Driverclassname = Oracle.jdbc.driver.OracleDriver
Jdbc_url = Jdbc:oracle:thin: @localhost: 1521:dbname
Jdbc_username = Test
Jdbc_password = test-related jar package (Ojdbc14.jar) MySQL connection configuration Hibernate.dialect = Org.hibernate.dialect.MySQLDialect
Driverclassname = Com.mysql.jdbc.Driver
Jdbc_url = Jdbc:mysql://localhost:3306/sshf?useunicode=true&characterencoding=utf-8
Jdbc_username = Test
Jdbc_password = Test SQL Server Connection Configuration Hibernate.dialect = Org.hibernate.dialect.SQLServerDialect
Driverclassname = Net.sourceforge.jtds.jdbc.Driver
Jdbc_url = Jdbc:jtds:sqlserver://localhost:1433;databasename=dbname
Jdbc_username = Test
Jdbc_password = Test the driver class for the above example uses the Jtds driver class, Jtds's jar package (eg. Jtds-1.2.jar) DB2 Connection Configuration Hibernate.dialect = Org.hibernate.dialect.DB2Dialect
Driverclassname = Com.ibm.db2.jdbc.app.DB2Driver
Jdbc_url = Jdbc:db2://localhost:5000/sample
Jdbc_username = Test
Jdbc_password = Test the driver class used is: Com.ibm.db2.jdbc.app.DB2Driver, related jar package (Db2jcc.jar) Sybase connection Configuration Hibernate.dialect = Org.hibernate.dialect.SybaseAnywhereDialect
Driverclassname = com.sybase.jdbc.SybDrive
Jdbc_url = Jdbc:sybase:tds:localhost:5007/mydb
Jdbc_username = Test
Jdbc_password = Test the driver class used is: Com.sybase.jdbc.SybDrive, related jar package (Jconn3.jar) PostgreSQL connection Configuration Hibernate.dialect = Org.hibernate.dialect.PostgreSQLDialect
Driverclassname = Org.postgresql.Driver
Jdbc_url = Jdbc:postgresql://localhost/mydb
Jdbc_username = Test
Jdbc_password = Test the driver class used above is: com.informix.jdbc.IfxDrive, related jar package (POSTGRESQL-8.1-405.JDBC3)
Spring 4 configuration DataSource Four Ways
1. Using Org.springframework.jdbc.datasource.DriverManagerDataSource
Note: Drivermanagerdatasource establishes a connection as long as there is a connection to create a new connection, there is no connection pooling role.
<bean id= "DataSource" class= "Org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name= "Driverclassname" ><value>${jdbc.driverClassName}</value></property>
<property name= "url" ><value>${jdbc.url}</value></property>
<property name= "username" ><value>${jdbc.username}</value></property>
<property name= "Password" ><value>${jdbc.password}</value></property>
</bean>
2. Using Org.apache.commons.dbcp.BasicDataSource
Description: This is a recommended way to configure the data source, which really uses the connection pooling technology
<bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" >
<property name= "Driverclassname" >
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name= "url" >
<value>jdbc:oracle:thin: @localhost:1521:orcl</value>
</property>
<property name= "username" >
<value>test</value>
</property>
<property name= "Password" >
<value>test</value>
</property>
<property name= "Maxactive" >
<value>255</value>
</property>
<property name= "Maxidle" >
<value>2</value>
</property>
<property name= "Maxwait" >
<value>120000</value>
</property>
</bean>
3. Using Org.springframework.jndi.JndiObjectFactoryBean
Description: Jndiobjectfactorybean is able to get datasource through Jndi
<bean id= "DataSource" class= "Org.springframework.jndi.JndiObjectFactoryBean" >
<property name= "Jndiname" ><value>java:comp/env/jdbc/roseindiadb_local</value></property >
</bean>
4. Using Com.mchange.v2.c3p0.ComboPooledDataSource
<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "Close" >
<property name= "Driverclass" value= "Oracle.jdbc.driver.OracleDriver"/>
<property name= "Jdbcurl" value= "Jdbc:oracle:thin: @localhost: 1521:ora9i"/>
<property name= "User" value= "admin"/>
<property name= "password" value= "1234"/>
</bean>
Summary: The first of 4 ways does not use connection pooling, so it is less useful in projects, and the third Way is to configure the data source in the Web server, which is not convenient for deployment.
It is recommended to configure the data source using the 2nd, 4 method, which is explained in detail below. If you want to configure the data source in a third way in Web server, see Tomcat configuration DataSource
<!--MySql driver eg. mysql-connector-java-5.0.4-bin.jar--> <property name= "dialect" >org.hibernate.dialect.mysqldialect</ property> <property name= "Connection.driver_class" >com.mysql.jdbc.Driver</property> <!--jdbc URL --<property name= "Connection.url" >jdbc:mysql://localhost/dbname?characterencoding=gb2312</property > <!--database username-<property name= "Connection.username" >root</property> <!--database Password--<PR Operty name= "Connection.password" >root</property>
<!--Sql Server driver eg. jtds-1.2.jar--> <property name= "dialect" >org.hibernate.dialect.SQLServerDialect</property> < Property Name= "Connection.driver_class" >net.sourceforge.jtds.jdbc.Driver</property> <!--jdbc URL-- > <property name= "Connection.url" >jdbc:jtds:sqlserver://localhost:1433;databasename=dbname</property > <!--database username-<property name= "Connection.username" >sa</property> <!--database Password--<prop Erty name= "Connection.password" ></property>
<!--Oracle driver ojdbc14.jar--> <property name= "dialect" >org.hibernate.dialect.oracledialect</ property> <property name= "Connection.driver_class" >oracle.jdbc.driver.OracleDriver</property> < !--JDBC URL--<property name= "Connection.url" >jdbc:oracle:thin: @localhost:1521:dbname</property> <!--database Username-<property name= "Connection.username" >test</property> <!--Database Password--< Property Name= "Connection.password" >test</property>
RDBMS dialect
DB2 |
Org.hibernate.dialect.DB2Dialect |
DB2 as/400 |
Org.hibernate.dialect.DB2400Dialect |
DB2 OS390 |
Org.hibernate.dialect.DB2390Dialect |
PostgreSQL |
Org.hibernate.dialect.PostgreSQLDialect |
Mysql |
Org.hibernate.dialect.MySQLDialect |
MySQL with InnoDB |
Org.hibernate.dialect.MySQLInnoDBDialect |
MySQL with MyISAM |
Org.hibernate.dialect.MySQLMyISAMDialect |
Oracle (any version) |
Org.hibernate.dialect.OracleDialect |
Oracle 9i/10g |
Org.hibernate.dialect.Oracle9Dialect |
Sybase |
Org.hibernate.dialect.SybaseDialect |
Sybase Anywhere |
Org.hibernate.dialect.SybaseAnywhereDialect |
Microsoft SQL Server |
Org.hibernate.dialect.SQLServerDialect |
SAP DB |
Org.hibernate.dialect.SAPDBDialect |
Informix |
Org.hibernate.dialect.InformixDialect |
Hypersonicsql |
Org.hibernate.dialect.HSQLDialect |
Ingres |
Org.hibernate.dialect.IngresDialect |
Progress |
Org.hibernate.dialect.ProgressDialect |
Mckoi SQL |
Org.hibernate.dialect.MckoiDialect |
Interbase |
Org.hibernate.dialect.InterbaseDialect |
Pointbase |
Org.hibernate.dialect.PointbaseDialect |
Frontbase |
Org.hibernate.dialect.FrontbaseDialect |
Firebird |
Org.hibernate.dialect.FirebirdDialect |
Hibernate's dialect Daquan