Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java resultset to table

public static DefaultTableModel buildTableModel(ResultSet rs)
        throws SQLException {

    ResultSetMetaData metaData = rs.getMetaData();

    // names of columns
    Vector<String> columnNames = new Vector<String>();
    int columnCount = metaData.getColumnCount();
    for (int column = 1; column <= columnCount; column++) {
        columnNames.add(metaData.getColumnName(column));
    }

    // data of the table
    Vector<Vector<Object>> data = new Vector<Vector<Object>>();
    while (rs.next()) {
        Vector<Object> vector = new Vector<Object>();
        for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
            vector.add(rs.getObject(columnIndex));
        }
        data.add(vector);
    }

    return new DefaultTableModel(data, columnNames);

}
Comment

PREVIOUS NEXT
Code Example
Java :: The superclass "jakarta.servlet.http.HttpServlet" was not found on the Java Build Path 
Java :: spring logback configuration 
Java :: java map remove all null values 
Java :: how to call a static method in java 
Java :: sort a list in java according to last name 
Java :: feign client url from properties 
Java :: map.keyset in java 
Java :: how to change background color of grid in grid layout in android 
Java :: android studio space 
Java :: java load jar at runtime 
Java :: java continue statement 
Java :: processing pi 
Java :: java developer interview questions 
Java :: what is the max size of array in java 
Java :: how to take binary input in java 
Java :: java delete element from list 
Java :: remove duplicates from list java 
Java :: maths trivia in java 
Java :: convert from integer to character java 
Java :: string length java 
Java :: compare 2 hashmap 
Java :: java to kotlin 
Java :: how do you handle exceptions in java 
Java :: java long literal 
Java :: why string is immutable in java 
Java :: |= java operation 
Java :: eclipse versioning .classpath 
Java :: netbens setdefaultbutton 
Java :: control flow graph generator 
Java :: set the content of a Jlist from an other Jlist (Swing) 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =