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