import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException;
public class connTest {
public static void main(String[] args) throws Exception { Connection conn = null; PreparedStatement pStmt = null; ResultSet rs = null; ResultSetMetaData rsmd = null; String sql = ""; int numberOfColumn = 0;
try { Class.forName("cubrid.jdbc.driver.CUBRIDDriver"); conn = DriverManager.getConnection("jdbc:cubrid:127.0.0.1:33000:db_name:::", "db_user", "db_pass"); } catch (Exception e) { e.printStackTrace(); }
sql = "SELECT * FROM TEST LIMIT 10";
try { pStmt = conn.prepareStatement(sql); rs = pStmt.executeQuery(); rsmd = rs.getMetaData(); numberOfColumn = rsmd.getColumnCount();
while (rs.next()) { for (int i = 1; i <= numberOfColumn; i++) System.out.print(rs.getString(i) + " "); System.out.println(""); } } catch (SQLException e) { e.printStackTrace(); } } }