当前位置: 技术问答>java相关
想要得到某个表都有哪些属性? 有分给!
来源: 互联网 发布时间:2015-06-28
本文导语: 在oracle里用desc tabname 能看到tabname表都有什么属性 但我在jsp里这么用不行: String sqlstr="desc tabname"; ResultSet RS=stmt.executeQuery(sqlstr); 提示错误:javax.servlet.ServletException: ORA-00900: invalid SQL statement 我要怎样才能取得...
在oracle里用desc tabname 能看到tabname表都有什么属性
但我在jsp里这么用不行:
String sqlstr="desc tabname";
ResultSet RS=stmt.executeQuery(sqlstr);
提示错误:javax.servlet.ServletException: ORA-00900: invalid SQL statement
我要怎样才能取得该表的各个属性呢?
但我在jsp里这么用不行:
String sqlstr="desc tabname";
ResultSet RS=stmt.executeQuery(sqlstr);
提示错误:javax.servlet.ServletException: ORA-00900: invalid SQL statement
我要怎样才能取得该表的各个属性呢?
|
http://www.csdn.net/Expert/TopicView1.asp?id=444354
|
ResultSetMetaData类的getColumnTypeName方法
|
ResultSetMetaData类的getColumnTypeName方法
|
给一个例子慢慢看吧:)
import java.io.*;
import java.util.*;
import java.sql.*;
public class JDBCBean {
String classname ; // JDBC driver class
String url ;
String username ;
String password ;
String query ; // the SQL statement.
int rows, cols; // the number of rows and columns of the result.
Vector result;
public void setClassname(String classname) {
this.classname = classname;
}
public String getClassname() {
return classname;
}
public void setUrl(/tech-qa-java/String url/index.html) {
this.url = url;
}
public String getUrl(){
return url;
}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setQuery(String query) {
this.query = query;
}
public String getQuery() {
return query;
}
protected void go()
throws ClassNotFoundException, SQLException
{
// Load the JDBC driver
Class.forName(classname);
// get the connection to the database
Connection con = DriverManager.getConnection(url, username,
password);
// create and execute the query
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData rsmd = rs.getMetaData();
cols = rsmd.getColumnCount();
rows = 0;
result = new Vector();
String s[] = new String[cols];
for (int i=1; i
import java.io.*;
import java.util.*;
import java.sql.*;
public class JDBCBean {
String classname ; // JDBC driver class
String url ;
String username ;
String password ;
String query ; // the SQL statement.
int rows, cols; // the number of rows and columns of the result.
Vector result;
public void setClassname(String classname) {
this.classname = classname;
}
public String getClassname() {
return classname;
}
public void setUrl(/tech-qa-java/String url/index.html) {
this.url = url;
}
public String getUrl(){
return url;
}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setQuery(String query) {
this.query = query;
}
public String getQuery() {
return query;
}
protected void go()
throws ClassNotFoundException, SQLException
{
// Load the JDBC driver
Class.forName(classname);
// get the connection to the database
Connection con = DriverManager.getConnection(url, username,
password);
// create and execute the query
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData rsmd = rs.getMetaData();
cols = rsmd.getColumnCount();
rows = 0;
result = new Vector();
String s[] = new String[cols];
for (int i=1; i
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。