找到你要的答案

Q:how to know the column data type in sql by passing attribute name from swings

Q:如何通过从波动属性名称知道SQL中的列的数据类型

I want to know the column data type in sql by passing attribute name from swings

Here is the detailed explanation with ex:

create table student(rollnumber varchar2(15),name varchar2(40));

from the front end GUI application(swings), I retrieve column names of student table by passing student as an argument and again I pass column names(rollnumbers,name) as arguments, here I want example code(in java) for to know data type of that particular column name(rollnumber,student), please give me guidance for this problem

我想通过从波动属性名称知道SQL中的列的数据类型

以下是详细的解释与EX:

create table student(rollnumber varchar2(15),name varchar2(40));

from the front end GUI application(swings), I retrieve column names of student table by passing student as an argument and again I pass column names(rollnumbers,name) as arguments, here I want example code(in java) for to know data type of that particular column name(rollnumber,student), please give me guidance for this problem

answer1: 回答1:

Something like this should work:

public String getColumnType(Connection conn, String columnName)
        throws SQLException {
    try (PreparedStatement ps = conn.prepareStatement("SELECT "
            + columnName + " FROM student")) {
        return ps.getMetaData().getColumnTypeName(1);
    }
}

For more details see ResultSetMetaData documentation.

像这样的东西应该工作:

public String getColumnType(Connection conn, String columnName)
        throws SQLException {
    try (PreparedStatement ps = conn.prepareStatement("SELECT "
            + columnName + " FROM student")) {
        return ps.getMetaData().getColumnTypeName(1);
    }
}

详情请看结果集元数据文件。

java  swing  jdbc