怎样读取表名
本文导语: 对于Oracle数据库 select * from ctxsys.dr$class 怎样在Java中读取(ctxsys与dr$class)的信息 | 下面的程序是bea的一个servlet的例子,可以用来获取数据库表的信息。 累似于:desc 表名。 你可以仔细地看看ResultSe...
select * from ctxsys.dr$class
怎样在Java中读取(ctxsys与dr$class)的信息
|
累似于:desc 表名。
你可以仔细地看看ResultSetMetaData的说明,在j2sdk的java.sql包下面。
package jdbc;
import java.sql.*;
import java.util.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class simplesql extends HttpServlet {
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("Hello datasource!");
out.println("
");
out.println("simplesql.java Attempting connection....");
java.sql.Connection conn = null;
java.sql.Statement stmt = null;
try {
// ============== Make connection to database ==================
// Obtain a Datasource connection from the WebLogic JNDI tree.
// Get a context for the JNDI look up
Context ctx = new InitialContext();
// Look up myDataSource
javax.sql.DataSource ds
= (javax.sql.DataSource) ctx.lookup ("weblogic.jdbc.jts.oraclePool");
//Create a connection object
conn = ds.getConnection();
out.println("
Connection successful...
Executing SQL...
");
// execute some SQL statements to demonstrate the connection.
stmt = conn.createStatement();
stmt.execute("select * from notebook");
ResultSet rs = stmt.getResultSet();
out.println("Querying data ...
");
while (rs.next())
{
out.println("
TITLE: " + rs.getString("title") +
"
CONTENT: " + rs.getString("content") + "");
}
//读取表的信息
ResultSetMetaData rsmd = rs.getMetaData();
out.println("Querying table meta data...
");
out.println("Number of Columns: " + rsmd.getColumnCount() + "");
for (int i = 1; i
您可能感兴趣的文章:
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。