Skip to content

Instantly share code, notes, and snippets.

@jayden-lee
Created January 10, 2019 14:29
Show Gist options
  • Save jayden-lee/40002eb86e0dbc30a99f4896470b2a8a to your computer and use it in GitHub Desktop.
Save jayden-lee/40002eb86e0dbc30a99f4896470b2a8a to your computer and use it in GitHub Desktop.
Tibero JDBC Connection Example
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
/**
* Tibero DBMS Connection Example
*
* @author jayden-lee
*/
public class TiberoConnection {
private String ip = "Your_IP";
private String port = "8629";
private String database = "Your_Database";
private String user = "Your_ID";
private String password = "Your_PassWord";
private final String DRIVER_NAME = "com.tmax.tibero.jdbc.TbDriver";
private final String TIBERO_JDBC_URL = "jdbc:tibero:thin:@" + ip + ":" + port + ":" + database;
private Connection conn = null;
/**
* default constructor
*/
public TiberoConnection() {
// empty
}
public static void main(String[] args) {
// create tiberoConnection instance
TiberoConnection tiberoConnection = new TiberoConnection();
// connect
tiberoConnection.connect();
// execute sample query
tiberoConnection.executeQuery();
// disconnect
tiberoConnection.disconnect();
}
/**
* create tibero connection instance
*/
private void connect() {
try {
Class.forName(DRIVER_NAME);
} catch (ClassNotFoundException e) {
System.err.println("Class Not Found");
System.exit(1);
}
try {
conn = DriverManager.getConnection(TIBERO_JDBC_URL, user, password);
} catch (SQLException e) {
System.err.println("DB Connection Error");
System.exit(1);
}
}
/**
* execute sample query
*/
private void executeQuery() {
String sampleQuery = "select * from all_users";
try (Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sampleQuery)) {
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
System.out.print(rsmd.getColumnTypeName(i) + " ");
}
System.out.println();
while (rs.next()) {
for (int i = 1; i <= columnCount; i++) {
System.out.print(rs.getObject(i) + " ");
}
System.out.println();
}
} catch (SQLException ex) {
System.err.println("Execute sample query Error");
System.exit(1);
}
}
/**
* disconnect
*/
private void disconnect() {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
System.err.println("Disconnect Error");
System.exit(1);
}
}
}
}
@ngoduyhien
Copy link

do you know where to download com.tmax.tibero.jdbc.TbDriver ?

@johanjah
Copy link

johanjah commented Oct 3, 2022

do you know where to download com.tmax.tibero.jdbc.TbDriver ?

Download here (extract from tibero zip installer, not convenience way but this is my recomendation)
https://technet.tmaxsoft.com/en/front/download/findDownloadList.do?cmProductCode=0301

or

Download from maven repository (not updated but useful)
https://mvnrepository.com/artifact/jdbc.tibero/tibero

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment