EsgynDB 简单步骤测试JDBC能否连通数据库
有时候我们会发现某个应用通过JDBC接口无法连通数据库,但从其他环境中是可以正常连接目标数据库的,为了排除是应用本身的问题,我们可以构建一个简单的JDBC测试程序来验证机器到数据库的连通性。主要步骤为:
- 编写简单的Java测试程序TestConnEsg.java,内容如下
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
public class TestConnEsg {
protected static String url = "jdbc:t4jdbc://10.19.41.65:23400,10.19.41.66:23400,10.19.41.67:23400/:schema=v7dev;maxStatements=400;connectionTimeout=0;clipVarchar=1";
private static String usr = "trafodion";
private static String pwd = "traf123";
private static final String driver = "org.trafodion.jdbc.t4.T4Driver";
private static Connection conn = null;
private static Statement stmt = null;
private static ResultSet rs = null;
public static void main(String[] args) throws Exception {
try {
Class.forName(driver);
println_message("loaded driver");
println_message("jdbc url [" + url + "]");
try {
conn = DriverManager.getConnection(url, usr, pwd);
} catch (Exception e) {
e.printStackTrace();
}
println_message("get success connection");
conn.setAutoCommit(false);
PreparedStatement stmt = conn.prepareStatement("select sysdate from dual");
rs = stmt.executeQuery();
conn.commit();
conn.close();
} finally {
if (conn != null) {
conn.close();
}
}
}
public static void println_message(String msg) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(format.format(new Date()) + " -> " + msg);
}
}准备EsgynDB数据库对应版本驱动包
使用java命令测试JDBC代码
(注:需要使用-cp引入依赖包)- 来源 https://blog.csdn.net/Post_Yuan/article/details/107235406?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164860649116780274180189%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164860649116780274180189&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~times_rank-7-107235406.142^v5^pc_search_result_control_group,143^v6^control&utm_term=ESGYNDB&spm=1018.2226.3001.4187
相关文章