java数据库连接:
Access 数据库连接:
1.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
2.DriverManager.getConnection("jdbc:odbc:[dsn]"); 注:dsn为数据源
MySql 数据库连接:
1.Class.forName("com.mysql.jdbc.Driver");
2.DriverManager.getConnection("jdbc:mysql://localhost/[DataBase name]?user=root&password=yuyang")
Oracle(thin)数据库连接:
1.Class.forName("oracle.jdbc.driver.OracleDriver");
2.DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:[DataBase Name]","scott","tiger");
本机专用:
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
Oracle(OCI driver)数据库连接:
1.Class.forName("oracle.jdbc.driver.OracleDriver");
2.DriverManager.getConnection("jdbc:oracle:oci8:@localhost:1521:[DataBase Name]","scott","tiger");
Microsoft SQL Server 2005数据库连接:
1.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
2.DriverManager.getConnection("jdbc:sqlserver://localhost:1433;database=MySchool;user=sa;password=yuyang");
(注:如果计算机中安装Dr.COM 宽带登录客户端软件,且处于运行状态,则连接数据库读取数据库时将会出现如下异常:Unrecognized Windows Sockets error: 997: recv failed
如果想运行,必须先把Dr.COM这个软件停掉方可)
Microsoft SQL Server 2000
一.Microsoft SQL Server:
1.Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
2.DriverManager.getConnection
("jdbc:microsoft:sqlserver://localhost:1433;databasename=MySchool","sa","yuyang");
二.Microsoft SQL Server(jTDS driver):
1.Class.forName("net.sourceforge.jtds.jdbc.Driver")
2.DriverManager.getConnection
("jdbc:jtds:sqlserver://localhost:1433/MySchool","sa","yuyang");
c#数据库连接:
Access数据库连接:
string ConStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=[Access DataBase Name]";
Connection con=new Connection(ConStr);
SQL Server 数据库连接:
string ConStr="Data source=.;Initial Catalog=pubs;User ID=sa";
Data Source=服务器名;Initial Catalog=数据库名;User ID=用户名;Pwd=密码
Access 数据库连接:
1.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
2.DriverManager.getConnection("jdbc:odbc:[dsn]"); 注:dsn为数据源
MySql 数据库连接:
1.Class.forName("com.mysql.jdbc.Driver");
2.DriverManager.getConnection("jdbc:mysql://localhost/[DataBase name]?user=root&password=yuyang")
Oracle(thin)数据库连接:
1.Class.forName("oracle.jdbc.driver.OracleDriver");
2.DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:[DataBase Name]","scott","tiger");
本机专用:
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
Oracle(OCI driver)数据库连接:
1.Class.forName("oracle.jdbc.driver.OracleDriver");
2.DriverManager.getConnection("jdbc:oracle:oci8:@localhost:1521:[DataBase Name]","scott","tiger");
Microsoft SQL Server 2005数据库连接:
1.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
2.DriverManager.getConnection("jdbc:sqlserver://localhost:1433;database=MySchool;user=sa;password=yuyang");
(注:如果计算机中安装Dr.COM 宽带登录客户端软件,且处于运行状态,则连接数据库读取数据库时将会出现如下异常:Unrecognized Windows Sockets error: 997: recv failed
如果想运行,必须先把Dr.COM这个软件停掉方可)
Microsoft SQL Server 2000
一.Microsoft SQL Server:
1.Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
2.DriverManager.getConnection
("jdbc:microsoft:sqlserver://localhost:1433;databasename=MySchool","sa","yuyang");
二.Microsoft SQL Server(jTDS driver):
1.Class.forName("net.sourceforge.jtds.jdbc.Driver")
2.DriverManager.getConnection
("jdbc:jtds:sqlserver://localhost:1433/MySchool","sa","yuyang");
c#数据库连接:
Access数据库连接:
string ConStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=[Access DataBase Name]";
Connection con=new Connection(ConStr);
SQL Server 数据库连接:
string ConStr="Data source=.;Initial Catalog=pubs;User ID=sa";
Data Source=服务器名;Initial Catalog=数据库名;User ID=用户名;Pwd=密码