日期:2014-05-16  浏览次数:20477 次

java连接各种数据库
  1. 再用光在博客找就行了,呵呵
  2. 1、Oracle8/8i/9i数据库(thin模式) ??
  3. ??
  4. Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); ??
  5. ??
  6. String?url="jdbc:oracle:thin:@localhost:1521:orcl"; ??
  7. ??
  8. //orcl为数据库的SID ??
  9. ??
  10. String?user="test"; ??
  11. ??
  12. String?password="test"; ??
  13. ??
  14. Connection?conn=?DriverManager.getConnection(url,user,password); ??
  15. ??
  16. 2、DB2数据库 ??
  17. ??
  18. Class.forName("com.ibm.db2.jdbc.app.DB2Driver?").newInstance(); ??
  19. ??
  20. String?url="jdbc:db2://localhost:5000/sample"; ??
  21. ??
  22. //sample为你的数据库名 ??
  23. ??
  24. String?user="admin"; ??
  25. ??
  26. String?password=""; ??
  27. ??
  28. Connection?conn=?DriverManager.getConnection(url,user,password); ??
  29. ??
  30. 3、Sql?Server7.0/2000数据库 ??
  31. ??
  32. Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); ??
  33. ??
  34. String?url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb"; ??
  35. ??
  36. //mydb为数据库 ??
  37. ??
  38. String?user="sa"; ??
  39. ??
  40. String?password=""; ??
  41. ??
  42. Connection?conn=?DriverManager.getConnection(url,user,password); ??
  43. ??
  44. 4、Sybase数据库 ??
  45. ??
  46. Class.forName("com.sybase.jdbc.SybDriver").newInstance(); ??
  47. ??
  48. String?url?="?jdbc:sybase:Tds:localhost:5007/myDB"