java中连接Mysql的方法与连接SqlServer的方法有区别吗?

java中连接Mysql的方法与连接SqlServer的方法有区别吗?
如果有,区别在哪里?

1、驱动程序不同

2、SqlServer可以用桥接(JDBC-ODBC)和直连(JDBC,但要打补丁对于2000来说);Mysql只能用直连。
温馨提示:内容为网友见解,仅供参考
第1个回答  2007-12-06
String driverClassName = ...;
String url = ....;
String user = ....;
String pw = ....;

// java代码.
Class.forName(driverClassName);
Connection con = DriverManager.getConnection(url, user, pw);

连不同的数据库,java代码是一样的,只是前面列出的4个变量值不同。
通常情况都是通过配置文件指定那4个值,这样只要修改配置文件,就可以连接不同的数据库。
第2个回答  2007-12-06
## MySQL

hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc\:mysql\://localhost\:3306/ra21?useUnicode\=true&characterEncoding\=gb2312
hibernate.connection.username=root
hibernate.connection.password=88888888

## MS SQL Server

#hibernate.dialect net.sf.hibernate.dialect.SQLServerDialect
#hibernate.connection.username sa
#hibernate.connection.password sa

## Microsoft Driver (not recommended!)
#hibernate.connection.driver_class com.microsoft.jdbc.sqlserver.SQLServerDriver
#hibernate.connection.url jdbc:microsoft:sqlserver://1E1;DatabaseName=test;SelectMethod=cursor
第3个回答  2007-12-05
驱动不一样,连接字符串不一样,建议用连接Mysql,连SqlServer会出现很多异想不到的问题!
第4个回答  2007-12-06
驱动包不一样(driver,URL,user,password也不一样),
其他的操作代码都一样
相似回答