java与数据库的连接
1.1、Oracle8/8i/9i数据库(thin模式)
2.
3.Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
4.
5.String url="jdbc:oracle:thin:@localhost:1521:orcl";
6.
7.//orcl为数据库的SID
8.
9.String user="test";
10.
11.String password="test";
12.
13.Connection conn= DriverManager.getConnection(url,user,password);
14.
15.2、DB2数据库
16.
17.Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
18.
19.String url="jdbc:db2://localhost:5000/sample";
20.
21.//sample为你的数据库名
22.
23.String user="admin";
24.
25.String password="";
26.
27.Connection conn= DriverManager.getConnection(url,user,password);
28.
29.3、Sql Server7.0/2000数据库
30.
31.Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
32.
33.String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
34.
35.//mydb为数据库
36.
37.String user="sa";
38.
39.String password="";
40.
41.Connection conn= DriverManager.getConnection(url,user,password);
42.
43.4、Sybase数据库
44.
45.Class.forName("com.sybase.jdbc.SybDriver").newInstance();
46.
47.String url =" jdbc:sybase:Tds:localhost:5007/myDB";
48.
49.//myDB为你的数据库名
50.
51.Properties sysProps = System.getProperties();
52.
53.SysProps.put("user","userid");
54.
55.SysProps.put("password","user_password");
56.
57.Connection conn= DriverManager.getConnection(url, SysProps);
58.
59.5、Informix数据库
60.
61.Class.forName("com.informix.jdbc.IfxDriver").newInstance();
62.
63.String url =
64.
65."jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
66.
67.user=testuser;password=testpassword";
68.
69.//myDB为数据库名
70.
71.Connection conn= DriverManager.getConnection(url);
72.
73.6、MySQL数据库
74.
75.Class.forName("org.gjt.mm.mysql.Driver").newInstance();
76.
77.String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
78.
79.//myDB为数据库名
80.
81.Connection conn= DriverManager.getConnection(url);
82.
83.7、PostgreSQL数据库
84.
85.Class.forName("org.postgresql.Driver").newInstance();
86.
87.String url ="jdbc:postgresql://localhost/myDB"
88.
89.//myDB为数据库名
90.
91.String user="myuser";
92.
93.String password="mypassword";
94.
95.Connection conn= DriverManager.getConnection(url,user,password);