日期:2014-05-18  浏览次数:20798 次

orcla jdbc 连接的例子 谁有???我忘记了 急用!!!100分
数据库名tct108
用户名site_test
密码.......
速度给分 成信!!!!

------解决方案--------------------
Class.forName( "oracle.jdbc.driver.OracleDriver" ); 
cn = DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:tct108", "site_test", "......");

MyDbComputerNameOrIP 替换你的oracle数据库ip地址
------解决方案--------------------
探讨
Class.forName( "oracle.jdbc.driver.OracleDriver" );
Connection cn = DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL", sUsr, sPwd );

------解决方案--------------------
Java code

public static void main(String[] args) {
        Connection conn = null;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            conn = DriverManager.getConnection(
                    "jdbc:oracle:thin:@localhost:1521:tct108", "site_test",
                    "...");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if (conn != null)
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
        }
    }

------解决方案--------------------
Java code

public class dbmanger {
      private String driver="oracle.jdbc.driver.OracleDriver";
      private String user="site_test ";
      private String password="";
      private String url="jdbc:oraclethin:@MyDbComputerNameOrIP/tct108";
      private Connection con=null;
      public dbmanger() {
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            con=DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
      }
      public Connection getConnection() {
          if(con==null) {
              try {
                con=DriverManager.getConnection(url,user,password);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
          }
          return con;
      }
      public void close(){
          if(con!=null) {
              try {
                con.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
          }
      }
}

------解决方案--------------------

------解决方案--------------------
把本地硬盘里的图片存储到oracle数据库里blob的实现
------解决方案--------------------
上面朋友的做法都可以的

呵呵,建议楼主对基本的数据库连接方法要熟练使用
------解决方案--------------------
public static void main(String[] args) {
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:tct108", "site_test",
"...&qu