Chinaunix首页 | 论坛 | 博客
  • 博客访问: 48751
  • 博文数量: 25
  • 博客积分: 1415
  • 博客等级: 上尉
  • 技术积分: 270
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-13 05:50
文章分类

全部博文(25)

文章存档

2011年(5)

2010年(1)

2009年(19)

我的朋友

分类: Java

2010-02-26 00:34:43

访问isqlplus的地址是  
 
Java的连接oracle数据库的测试代码是:
/*
 * This sample can be used to check the JDBC installation.
 * Just run it and provide the connect information.  It will select
 * "Hello World" from the database.
 */
// You need to import the java.sql package to use JDBC
import java.sql.*;
// We import java.io to be able to read from the command line
import java.io.*;
class JdbcCheckup
{
 public static void main (String args []) throws SQLException, IOException
 {
  // Load the Oracle JDBC driver
  DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  // Prompt the user for connect information
  System.out.println ("Please enter information to test connection to the database");
  String user;
  String password;
  String database;
  user = readEntry ("user: ");
  int slash_index = user.indexOf ('/');
  if (slash_index != -1)
  {
     password = user.substring (slash_index + 1);
     user = user.substring (0, slash_index);
  }
  else
   password = readEntry ("password: ");
  database = readEntry ("database (a TNSNAME entry): ");
  
  System.out.print ("Connecting to the database...");
  System.out.flush ();
  
  System.out.println ("Connecting...");
  Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@" + database, 
                                 user, password);
  
  System.out.println ("connected.");
  
  // Create a statement
  Statement stmt = conn.createStatement ();
  // Do the SQL "Hello World" thing
  ResultSet rset = stmt.executeQuery ("select 'Hello World'from dual");
  while (rset.next ())
     System.out.println (rset.getString (1));
  // close the result set, the statement and connect
  rset.close();
  stmt.close();
  conn.close();
  System.out.println ("Your JDBC installation is correct.");
 }
 // Utility function to read a line from standard input
 static String readEntry(String prompt)
 {
  try {
   StringBuffer buffer = new StringBuffer();
   System.out.print(prompt);
   System.out.flush();
   int c = System.in.read();
   while (c != '\n' && c != -1)
   {
    buffer.append((char) c);
    c = System.in.read();
   }
   return buffer.toString().trim();
  }
  catch (IOException e)
  {
   return "";
  }
 }
}
 
;---------------------------------------------------------------
java jdbc驱动是文件\oracle\product\10.1.0\db_1\jdbc\lib\classes12.jar 加入动态库文件中就可以正确运行以上测试文件
 
阅读(374) | 评论(0) | 转发(0) |
0

上一篇:Beginning Linux Programming (pipes)

下一篇:Activity

给主人留下些什么吧!~~