查询字段名 我想查询sql server 中某表的所有字段的名字,怎么办? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select * from table_name;在mysql里可以 describe table_name;不知道MS SQlServer里行不行。。 select name from syscolumns where id =(select id from sysobjects where xtype='U' and name='表名') select 字段名 from 表名 import java.sql.*;public class chen { public static void main(String args[]) throws ClassNotFoundException, SQLException { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = null; try { con = DriverManager.getConnection("jdbc:odbc:regi"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } Statement stmt = null; try { stmt = con.createStatement(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } ResultSet rs = null; try { //调用Statement对象的executeQuery方法,创建一个代表”表“的ResultSet对象 //设定有变量rs引用 rs = stmt . executeQuery("select * from 表名"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } ResultSetMetaData mtdt = null; try { //通过rs调用ResultSet对象的getmetaData方法,获取rs记录集的有关资料,并返回 //值赋予ResultSetMetaData类型的变量mtdt; mtdt = rs.getMetaData(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } int nmb = mtdt.getColumnCount(); for(int i = 1; i < nmb; i++) { System.out.println(mtdt.getColumnClassName(i)+'\n'); System.out.println(mtdt.getColumnTypeName(i)+'\n'); } rs.close(); stmt.close(); con.close(); System.out.println("本表共有字段:"+nmb); }}//自己写个main方法测试吧。 关于JAVA中抽象类输入参数类型的问题? 求助swing图片按钮带按下效果 对线程有着太多的疑问,尤其是锁上之后! 请教一个数据库查询语句 怎么应用弹出式菜单 谁有Java编程思想第二版(Thinking in java second) 最近做一个自动化测试的,但是java怎样监控鼠标的行为 java获取泛型参数类型 请教JAVA怎么实现从一个中文文本中查到我定义的几个词汇 我有断JAVA代码没有读懂,请大家给看看,急用,在线等,请大家帮忙,谢谢。 tomcat 下 properties文件放哪里啊 怎么算字符串的长度?
在mysql里可以 describe table_name;不知道MS SQlServer里行不行。。
select name from syscolumns
where id =(select id from sysobjects where xtype='U' and name='表名')
public class chen { public static void main(String args[]) throws ClassNotFoundException, SQLException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:odbc:regi");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Statement stmt = null;
try {
stmt = con.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ResultSet rs = null;
try {
//调用Statement对象的executeQuery方法,创建一个代表”表“的ResultSet对象
//设定有变量rs引用
rs = stmt . executeQuery("select * from 表名");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ResultSetMetaData mtdt = null;
try {
//通过rs调用ResultSet对象的getmetaData方法,获取rs记录集的有关资料,并返回
//值赋予ResultSetMetaData类型的变量mtdt;
mtdt = rs.getMetaData();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int nmb = mtdt.getColumnCount();
for(int i = 1; i < nmb; i++)
{
System.out.println(mtdt.getColumnClassName(i)+'\n');
System.out.println(mtdt.getColumnTypeName(i)+'\n');
}
rs.close();
stmt.close();
con.close();
System.out.println("本表共有字段:"+nmb);
}
}
//自己写个main方法测试吧。