建议你看一下oracle带的帮助。/*
* This sample shows how to list all the names from the EMP table
*
* It uses the JDBC THIN driver. See the same program in the
* oci8 samples directory to see how to use the other drivers.
*/// You need to import the java.sql package to use JDBC
import java.sql.*;class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as <host>:<port>:<sid>. The example uses the short cut syntax.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@dlsun511:1721:dbms733",
"scott", "tiger"); // Create a Statement
Statement stmt = conn.createStatement (); // Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP"); // Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}
解决方案 »
- 多线程小问题求解释
- java 用httpClient 读取excel
- SWT有什么工具可以可视化编辑吗?
- jdk中的jre和jre有什么区别?
- 每次启动CSDN,就会不定期地出现报时的声音,这是怎么回事,能不能关掉它?
- 怎么interrupt线程
- 兄弟们:我想不通:为什么微软的CLR就是比JVM快那么多?真是见鬼了!是因为微软没有公开WINDOWS的源代码吗?那为什么在UNIX上,JVM一样的
- 如何在读取文件内容后,将文件内容清空(不用删除文件的方法)???!!!
- 明天放假;今天放分;中午结账
- java读取word文档 报错显示:The document is really a RTF file
- * * * * * * * * * * 客观评价,VJ++有哪些不好,哪些好? * * * * * * * * * *
- 一个很简单的问题,我不知道,请各位帮忙。
* This sample shows how to list all the names from the EMP table
*/// You need to import the java.sql package to use JDBC
import java.sql.*;class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); String url = "jdbc:oracle:oci8:@";
try {
String url1 = System.getProperty("JDBC_URL");
if (url1 != null)
url = url1;
} catch (Exception e) {
// If there is any security exception, ignore it
// and use the default
}
// Connect to the database
Connection conn =
DriverManager.getConnection (url, "scott", "tiger"); // Create a Statement
Statement stmt = conn.createStatement (); // Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP"); // Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1)); // Close the RseultSet
rset.close(); // Close the Statement
stmt.close(); // Close the connection
conn.close();
}
}
不知道你用的是什么环境,jb?还是想在AS下使用?