1提交Oracle驱动调用之前加载自定义的驱动的测试用例
This commit is contained in:
parent
bcc115c919
commit
e885e93b72
|
|
@ -29,6 +29,12 @@
|
|||
<version>5.1.36</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.oracle</groupId>
|
||||
<artifactId>ojdbc14</artifactId>
|
||||
<version>10.2.0.4.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
package test.ai.cloud.skywalking.plugin.oracle;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class MyDriver implements Driver {
|
||||
|
||||
private Driver realDriver;
|
||||
|
||||
static {
|
||||
try {
|
||||
DriverManager.registerDriver(new MyDriver());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public MyDriver() {
|
||||
|
||||
}
|
||||
|
||||
public Driver buildOracleDriver() {
|
||||
if (realDriver == null)
|
||||
realDriver = new oracle.jdbc.OracleDriver();
|
||||
|
||||
return realDriver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection connect(String url, Properties info) throws SQLException {
|
||||
System.out.println("MyDriver connect(String url, Properties info)");
|
||||
return buildOracleDriver().connect(url, info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsURL(String url) throws SQLException {
|
||||
System.out.println("MyDriver acceptsURL(String url)");
|
||||
return buildOracleDriver().acceptsURL(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
||||
System.out.println("MyDriver getPropertyInfo(String url, Properties info)");
|
||||
return buildOracleDriver().getPropertyInfo(url, info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
System.out.println("MyDriver getMajorVersion()");
|
||||
return buildOracleDriver().getMajorVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
System.out.println("MyDriver getMinorVersion()");
|
||||
return buildOracleDriver().getMajorVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean jdbcCompliant() {
|
||||
System.out.println("MyDriver jdbcCompliant()");
|
||||
return realDriver.jdbcCompliant();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
System.out.println("MyDriver getParentLogger()");
|
||||
return realDriver.getParentLogger();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package test.ai.cloud.skywalking.plugin.oracle;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-14.
|
||||
*/
|
||||
public class TestMyDriver {
|
||||
public static void main(String[] args) throws ClassNotFoundException, SQLException {
|
||||
Class.forName("test.ai.cloud.skywalking.plugin.oracle.MyDriver");
|
||||
String url = "jdbc:oracle:thin:@10.1.130.239:1521:ora";
|
||||
Connection con = DriverManager.getConnection(url, "edc_export", "edc_export");
|
||||
con.setAutoCommit(false);
|
||||
|
||||
PreparedStatement p0 = con.prepareStatement("select 1 from dual where 1=?");
|
||||
p0.setInt(1, 1);
|
||||
p0.execute();
|
||||
con.commit();
|
||||
con.close();
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue