EsgynDB 简单步骤测试JDBC能否连通数据库

2023年 8月 13日 79.7k 0

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); }}

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论