GVKun编程网logo

com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker的实例源码

2

在这里,我们将给大家分享关于com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker的实例源码的知识,同时也会涉及到如何更有效地2022

在这里,我们将给大家分享关于com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker的实例源码的知识,同时也会涉及到如何更有效地20220507 3. Integration - Enterprise JavaBeans (EJB) Integration、com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver、com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver 的区别、com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别的内容。

本文目录一览:

com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker的实例源码

com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker的实例源码

项目:the-vigilantes    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            System.out.println("The testBug20242() is ignored because required class isn't available:");
            ex.printstacktrace();
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }
}
项目:OpenVertretung    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            System.out.println("The testBug20242() is ignored because required class isn't available:");
            ex.printstacktrace();
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }
}
项目:ProyectoPacientes    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            System.out.println("The testBug20242() is ignored because required class isn't available:");
            ex.printstacktrace();
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }
}
项目:BibliotecaPS    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            System.out.println("The testBug20242() is ignored because required class isn't available:");
            ex.printstacktrace();
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }
}
项目:Geometry-wars    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            System.out.println("The testBug20242() is ignored because required class isn't available:");
            ex.printstacktrace();
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }
}
项目:TPKB    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }
}
项目:cloudera-cli-scripts    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }
}
项目:fil_project_mgmt_app_v2    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }   
}
项目:SMPT42    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }
}
项目:ForYou    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }   
}
项目:group-five    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }
}
项目:locaviewer    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }
}
项目:Gladiatus    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }   
}
项目:Jspad    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }   
}
项目:Trails    文件:DataSourceRegressionTest.java   
/**
 * Tests fix for BUG#20242 - MysqLValidConnectionChecker for JBoss doesn't
 * work with MysqLXADataSources.
 * 
 * @throws Exception if the test fails.
 */
public void testBug20242() throws Exception {
    if (versionMeetsMinimum(5,0)) {
        try {
            Class.forName("org.jboss.resource.adapter.jdbc.ValidConnectionChecker");
        } catch (Exception ex) {
            return; // class not available for testing
        }

        MysqLXADataSource xaDs = new MysqLXADataSource();
        xaDs.setUrl(dbUrl);

        MysqLValidConnectionChecker checker = new MysqLValidConnectionChecker();
        assertNull(checker.isValidConnection(xaDs.getXAConnection().getConnection()));
    }   
}
项目:fil_project_mgmt_app_v2    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl
            .loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance())
            .isValidConnection(this.conn);
}
项目:ForYou    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl
            .loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance())
            .isValidConnection(this.conn);
}
项目:Gladiatus    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl
            .loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance())
            .isValidConnection(this.conn);
}
项目:Jspad    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl
            .loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance())
            .isValidConnection(this.conn);
}
项目:Trails    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl
            .loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance())
            .isValidConnection(this.conn);
}
项目:the-vigilantes    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl.loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance()).isValidConnection(this.conn);
}
项目:OpenVertretung    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl.loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance()).isValidConnection(this.conn);
}
项目:ProyectoPacientes    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl.loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance()).isValidConnection(this.conn);
}
项目:BibliotecaPS    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl.loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance()).isValidConnection(this.conn);
}
项目:Geometry-wars    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl.loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance()).isValidConnection(this.conn);
}
项目:TPKB    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl.loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance()).isValidConnection(this.conn);
}
项目:cloudera-cli-scripts    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl.loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance()).isValidConnection(this.conn);
}
项目:SMPT42    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl.loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance()).isValidConnection(this.conn);
}
项目:group-five    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl.loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance()).isValidConnection(this.conn);
}
项目:locaviewer    文件:ConnectionRegressionTest.java   
public void testBug29106() throws Exception {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Class<?> checkerClass = cl.loadClass("com.MysqL.jdbc.integration.jboss.MysqLValidConnectionChecker");
    ((MysqLValidConnectionChecker) checkerClass.newInstance()).isValidConnection(this.conn);
}

20220507 3. Integration - Enterprise JavaBeans (EJB) Integration

20220507 3. Integration - Enterprise JavaBeans (EJB) Integration

前言

文档地址

作为一个轻量级容器,Spring 通常被认为是 EJB 的替代品。我们确实相信,对于大多数应用程序和用例来说,Spring 作为一个容器,结合它在事务领域的丰富支持功能,ORM 和 JDBC 访问,是一个比通过 EJB 容器和 EJB 实现等效功能更好的选择。

但是,需要注意的是,使用 Spring 并不妨碍您使用 EJB 。实际上,Spring 使得访问 EJB 和在其中实现 EJB 和功能变得更加容易。此外,使用 Spring 访问 EJB 提供的服务允许这些服务的实现以后在本地 EJB、远程 EJB 或 POJO (普通 Java 对象) 变体之间透明地进行切换,而不必更改客户端代码。

其他略

com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver

com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver

com.mysql.jdbc.Driver tocom.mysql.cj.jdbc.Driver

MySQL :: MySQL Connector/J 8.0 Developer Guide :: 4.3.1.3 Changes in the Connector/J API https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-api-changes.html

MySQL Connector/J 8.0 Developer Guide  /   ...  /  Changes in the Connector/J API

4.3.1.3 Changes in the Connector/J API

This section describes the changes to the Connector/J API going from version 5.1 to 8.0. You might need to adjust your API calls accordingly:

  • The name of the class that implements java.sql.Driver in MySQL Connector/J has changed from com.mysql.jdbc.Driver tocom.mysql.cj.jdbc.Driver. The old class name has been deprecated.

  • The names of these commonly-used interfaces have also been changed:

    • ExceptionInterceptor: from com.mysql.jdbc.ExceptionInterceptor to com.mysql.cj.exceptions.ExceptionInterceptor

    • StatementInterceptor: from com.mysql.jdbc.StatementInterceptorV2 to com.mysql.cj.interceptors.QueryInterceptor

    • ConnectionLifecycleInterceptor: from com.mysql.jdbc.ConnectionLifecycleInterceptor tocom.mysql.cj.jdbc.interceptors.ConnectionLifecycleInterceptor

    • AuthenticationPlugin: from com.mysql.jdbc.AuthenticationPlugin to com.mysql.cj.protocol.AuthenticationPlugin

    • BalanceStrategy: from com.mysql.jdbc.BalanceStrategy to com.mysql.cj.jdbc.ha.BalanceStrategy.

    •  

     

信息: Loading XML bean definitions from class path resource [Beans.xml]
Loading class `com.mysql.jdbc.Driver''. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver''. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ">

    <bean id="dataSource">
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://rm-2zeo.mysql.rds.aliyuncs.com:3306/vtest"/>
        <property name="username" value="u"/>
        <property name="password" value="I"/>
    </bean>

    <!-- Definition for studentJDBCTemplate bean -->
    <bean id="studentJDBCTemplate">
        <property name="dataSource"  ref="dataSource" />
    </bean>

</beans>

  

 mvn clean;mvn compile;mvn package;mvn install;

mvn 打包jar

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.tutorialspoint</groupId>
    <artifactId>HelloSpringJDBCMysql</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>

        <!-- Spring Core -->
        <!-- http://mvnrepository.com/artifact/org.springframework/spring-core -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.1.4.RELEASE</version>
        </dependency>

        <!-- Spring Context -->
        <!-- http://mvnrepository.com/artifact/org.springframework/spring-context -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.1.4.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.1.3.RELEASE</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.13</version>
        </dependency>

    </dependencies>
    <build>
        <!--使用的插件列表-->
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.tutorialspoint.MainApp</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <useUniqueVersions>false</useUniqueVersions>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>com.tutorialspoint.MainApp</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

  

[root@d java]# tree -I target
.
├── pom.xml
├── spring.iml
└── src
├── main
│   ├── java
│   │   └── com
│   │   └── tutorialspoint
│   │   ├── MainApp.java
│   │   ├── StudentDAO.java
│   │   ├── Student.java
│   │   ├── StudentJDBCTemplate.java
│   │   └── StudentMapper.java
│   └── resources
│   └── beans.xml
└── test
└── java

8 directories, 8 files
[root@d java]#

com.tutorialspoint.StudentDAO

package com.tutorialspoint;
import java.util.List;
import javax.sql.DataSource;
public interface StudentDAO {
/**
* This is the method to be used to initialize
* database resources ie. connection.
*/
public void setDataSource(DataSource ds);
/**
* This is the method to be used to create
* a record in the Student table.
*/
public void create(String name, Integer age);
/**
* This is the method to be used to list down
* a record from the Student table corresponding
* to a passed student id.
*/
public Student getStudent(Integer id);
/**
* This is the method to be used to list down
* all the records from the Student table.
*/
public List<Student> listStudents();
/**
* This is the method to be used to delete
* a record from the Student table corresponding
* to a passed student id.
*/
public void delete(Integer id);
/**
* This is the method to be used to update
* a record into the Student table.
*/
public void update(Integer id, Integer age);
}

com.tutorialspoint.Student

package com.tutorialspoint;
public class Student {
/**
CREATE TABLE Student(
ID INT NOT NULL AUTO_INCREMENT,
NAME VARCHAR(20) NOT NULL,
AGE INT NOT NULL,
PRIMARY KEY (ID)
);
* */
private Integer age;
private String name;
private Integer id;
public void setAge(Integer age) {
this.age = age;
}
public Integer getAge() {
return age;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
}

com.tutorialspoint.StudentMapper

package com.tutorialspoint;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
public class StudentMapper implements RowMapper<Student> {
public Student mapRow(ResultSet rs, int rowNum) throws SQLException {
Student student = new Student();
student.setId(rs.getInt("id"));
student.setName(rs.getString("name"));
student.setAge(rs.getInt("age"));
return student;
}
}

com.tutorialspoint.StudentJDBCTemplate

package com.tutorialspoint;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
public class StudentJDBCTemplate implements StudentDAO {
private DataSource dataSource;
private JdbcTemplate jdbcTemplateObject;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcTemplateObject = new JdbcTemplate(dataSource);
}
public void create(String name, Integer age) {
String SQL = "insert into Student (name, age) values (?, ?)";
jdbcTemplateObject.update( SQL, name, age);
System.out.println("Created Record Name = " + name + " Age = " + age);
return;
}
public Student getStudent(Integer id) {
String SQL = "select * from Student where id = ?";
Student student = jdbcTemplateObject.queryForObject(SQL,
new Object[]{id}, new StudentMapper());
return student;
}
public List<Student> listStudents() {
String SQL = "select * from Student";
List <Student> students = jdbcTemplateObject.query(SQL,
new StudentMapper());
return students;
}
public void delete(Integer id){
String SQL = "delete from Student where id = ?";
jdbcTemplateObject.update(SQL, id);
System.out.println("Deleted Record with ID = " + id );
return;
}
public void update(Integer id, Integer age){
String SQL = "update Student set age = ? where id = ?";
jdbcTemplateObject.update(SQL, age, id);
System.out.println("Updated Record with ID = " + id );
return;
}
}

com.tutorialspoint.MainApp

package com.tutorialspoint;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
//ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
//ApplicationContext context = new ClassPathXmlApplicationContext("/data/gateway/java/src/main/resources/beans.xml");
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
StudentJDBCTemplate studentJDBCTemplate =
(StudentJDBCTemplate)context.getBean("studentJDBCTemplate");
System.out.println("------Records Creation--------" );
studentJDBCTemplate.create("Zara", 11);
studentJDBCTemplate.create("Nuha", 2);
studentJDBCTemplate.create("Ayan", 15);
System.out.println("------Listing Multiple Records--------" );
List<Student> students = studentJDBCTemplate.listStudents();
for (Student record : students) {
System.out.print("ID : " + record.getId() );
System.out.print(", Name : " + record.getName() );
System.out.println(", Age : " + record.getAge());
}
System.out.println("----Updating Record with ID = 2 -----" );
studentJDBCTemplate.update(2, 20);
System.out.println("----Listing Record with ID = 2 -----" );
Student student = studentJDBCTemplate.getStudent(2);
System.out.print("ID : " + student.getId() );
System.out.print(", Name : " + student.getName() );
System.out.println(", Age : " + student.getAge());
}
}

 

 

[root@d java]# java -jar /data/gateway/java/target/HelloSpringJDBCMysql-0.0.1-SNAPSHOT-jar-with-dependencies.jar
Dec 03, 2018 3:11:06 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@133314b: startup date [Mon Dec 03 15:11:06 CST 2018]; root of context hierarchy
Dec 03, 2018 3:11:06 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [beans.xml]
------Records Creation--------
Created Record Name = Zara Age = 11
Created Record Name = Nuha Age = 2
Created Record Name = Ayan Age = 15
------Listing Multiple Records--------
ID : 1, Name : Zara, Age : 11
ID : 2, Name : Nuha, Age : 2
ID : 3, Name : Ayan, Age : 15
----Updating Record with ID = 2 -----
Updated Record with ID = 2
----Listing Record with ID = 2 -----
ID : 2, Name : Nuha, Age : 20
[root@d java]#

  

 

 

 

com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver 的区别

com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver 的区别

调试代码时,发现错误:

Loading class `com.mysql.jdbc.Driver''. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver''. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

在网上巴拉巴拉发现,原来:

com.mysql.jdbc.Driver 是 mysql-connector-java 5 中的;
com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6 中的。

1、JDBC 连接 Mysql5 com.mysql.jdbc.Driver:

spring:
# 数据库连接
datasource:
url: jdbc:mysql://192.168.1.1:3306/demo?useUnicode=true&characterEncoding=utf8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver

2、JDBC 连接 Mysql6 com.mysql.jdbc.Driver,需要指定时区serverTimezone:

spring:
# 数据库连接
datasource:
url: jdbc:mysql://192.168.1.1:3306/demo?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false
#    在设定时区的时候,如果设定serverTimezone=UTC,会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong,例如:
#                                           ?serverTimezone=Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver


com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别

com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别

 版本区别:

  com.mysql.jdbc.Driver 是 mysql-connector-java 5中的

  com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6中的

 

1、JDBC连接Mysql5 com.mysql.jdbc.Driver:

  driverClassName=com.mysql.jdbc.Driver
  url=jdbc:mysql://localhost:3306/jpa(?useUnicode=true&characterEncoding=utf8&useSSL=false)----可加可不加,建议加上
  username=root
  password=111

2、JDBC连接Mysql6 com.mysql.cj.jdbc.Driver, 需要指定时区serverTimezone:

  driverClassName=com.mysql.cj.jdbc.Driver
  url=jdbc:mysql://localhost:3306/jpa(?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false)------不加报错
  username=root
  password=111

备注:

        ****         如果mysql-connector-java用的6.0以上的,如下:

  <dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>6.0.6</version>
  </dependency>

              ****      但是你的driver用的还是com.mysql.jdbc.Driver,就会报错:

  Loading class ''com.mysql.jdbc.Driver''. This is deprecated. The new
  driver class is ''com.mysql.cj.jdbc.Driver''.
  The driver is automatically registered via the SPI
  and manual loading of the driver class is generally unnecessary.

    ****     此时需要把com.mysql.jdbc.Driver 改为com.mysql.cj.jdbc.Driver

&&&   还有一个警告:

WARN: Establishing SSL connection without server’s identity verification is not recommended.
According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection
must be established by default if explicit option isn’t set.
For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’.
You need either to explicitly disable SSL by setting useSSL=false,
or set useSSL=true and provide truststore for server certificate verification.

  不推荐不使用服务器身份验证来建立SSL连接。
  如果未明确设置,MySQL 5.5.45+, 5.6.26+ and 5.7.6+版本默认要求建立SSL连接。
  为了符合当前不使用SSL连接的应用程序,verifyServerCertificate属性设置为’false’。
  如果你不需要使用SSL连接,你需要通过设置useSSL=false来显式禁用SSL连接。
  如果你需要用SSL连接,就要为服务器证书验证提供信任库,并设置useSSL=true。

 

今天的关于com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker的实例源码的分享已经结束,谢谢您的关注,如果想了解更多关于20220507 3. Integration - Enterprise JavaBeans (EJB) Integration、com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver、com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver 的区别、com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别的相关知识,请在本站进行查询。

本文标签: