JAVA连接SQL的具体方法

来源:百度知道 编辑:UC知道 时间:2024/05/03 01:44:44
我是菜鸟,麻烦各位大虾说仔细点简单点易懂点。以前有些大虾说的太麻烦和深奥了,不是我们这些菜鸟所能理解滴。速度速度。帮忙帮忙。要具体点。最好有个例子讲解。

一下是常见数据库的连接

1、Oracle8/8i/9i数据库(thin模式)

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为数据库的SID
String user="test";
String password="test";
Connection conn= DriverManager.getConnection(url,user,password);

2、DB2数据库

Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String url="jdbc:db2://localhost:5000/sample"; //sample为你的数据库名
String user="admin";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);

3、SQL Server7.0/2000数据库

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
//mydb为数据库
String user="sa";
String password="