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=密码.
以上是我学习c#和java连接数据库时的一些经验总结,希望对朋友们学习java和数据库的连接有所帮助.
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/dreamlikesoft/archive/2009/12/17/5026953.aspx