Engineering Full Stack Apps with Java and JavaScript
import java.sql.Array;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class JDBCArrayClient {
public static void passArray() {
try {
Class.forName("oracle.jdbc.OracleDriver");
// Need to modify conn string, username and password as per your oracle installation.
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@<hostname>:<port>:<sid>", "username", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT emp_id, emp_skills from empnested");
while (rs.next()) {
Array e = rs.getArray("emp_skills");
String[] skills = (String[]) e.getArray();
System.out.println("Skills");
for (int i = 0; i < skills.length; i++) {
System.out.println(skills[i]);
}
}
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String args[]) {
passArray();
}
}