不知道你要连接什么数据库以下是Oracle oci连接的一个例子,你可以到http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/getsta.htm#1001200去看原文,不过可能要求你在oracle上注册 Although JdbcCheckup.java is a simple program, it demonstrates several important functions by executing the following:imports the necessary Java classes, including JDBC classes 
registers the JDBC driver 
connects to the database 
executes a simple query 
outputs the query results to your screen 
"First Steps in JDBC", describes these functions in greater detail. A listing of JdbcCheckup.java for the JDBC OCI driver appears below./*
 * 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:oci:@" + 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 "";
      }
   }
}

解决方案 »

  1.   

    http://www.yesky.com/SoftChannel/72342371945283584/20020423/1608282.shtml
      

  2.   

    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
    String url="jdbc:microsoft:sqlserver://192.168.1.2:1433;DatabaseName=fcr";
    /****SQLServer****/Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    String url="jdbc:oracle:thin:@192.168.1.114:1521:oratest";
                              //oratest为数据库的SID
    /********oracle*****/
    String user="sa";
    String password="sa";
    connection= DriverManager.getConnection(url,user,password);
    前提要有JDBC驱动
      

  3.   

    通过JDBC连接SQLSERVER 和 ORACLE 需要JDBC驱动包,
    SQLSERVER:msbase.jar,mssqlserver.jar,msutil.jar;
    ORACLE: classes111.zip或classes12.zip
      

  4.   

    package practise;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */import java.sql.*;class connectMSSQLSERVER {
      public static void main(String[] args) throws SQLException,
          ClassNotFoundException {    String dburl =
            "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=text";
        String user = "sa";
        String password = "password";
        try {
          Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
          Connection c = DriverManager.getConnection(dburl, user, password);      if (c.isClosed()) {
            System.out.println("error");
            return;
          }      c.setAutoCommit(false);
          Statement s = c.createStatement();
          ResultSet r = s.executeQuery("SELECT * FROM test");      while (r.next()) {
            System.out.println(r.getString(1) + r.getString("name"));
          }
          s.close();
          c.close();
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
      

  5.   

    http://java.net.cn/documents/20040903/38153129.html