I want to know the column data type in sql by passing attribute name from swings
我想通过从swings传递属性名称来了解sql中的列数据类型
Here is the detailed explanation with ex:
以下是对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
从前端GUI应用程序(swings),我通过传递学生作为参数来检索学生表的列名称,并再次将列名称(rollnumbers,name)作为参数传递,这里我想要示例代码(在java中)来了解数据该特定列名称的类型(rollnumber,student),请给我这个问题的指导
1 个解决方案
#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.
有关更多详细信息,请参阅ResultSetMetaData文档。
#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.
有关更多详细信息,请参阅ResultSetMetaData文档。