閺€鎯版 (0) +1 鐠э拷 (0) +1 闊拷 (0) +1
閺€鎯版閹存劕濮�閺屻儳婀呴弨鎯版>>

正在阅读:Java连接数据库谈Java连接数据库谈

2004-04-07 14:31 出处:CSDN 作者:PaleSting 责任编辑:sdq

  2.连接到数据库。
  
  根据您后台待连接的数据库不同,而有小小的差别。

  a)       连接到Oracle数据库。

  Connection connection = null ;

  try

  {

    //load the jdbc driver ;

    String driverName = “oracle.jdbc.driver.OracleDriver”;

    Class.forName(driverName).newInstance();

   //create a connection to the database;

    String serverName = “127.0.0.1”;

    String serverPort = “1521”;

    String serverID = “datebase1”

    String userName = “hello”;

    String userPsw = “world”;

    String url = “jdbc:oracle.thin:@” + serverName + “:” + serverPort + “:” + serverID ;

    Connection = DriverManager.getConnection(url , userName , userPsw);

  }

  catch(ClassNotFoundException e1)

  {

    //catch could not find database driver exception.

  }

  catch(SQLException e2)

  {

    //catch could not connect to the database exception.

  }

察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品
閹靛婧€鐠佸潡妫�閸ョ偛鍩屾い鍫曞劥