java 连接mysql 和sql server2008代码

这两天用java分别连接mysql和sql server2008代码。刚開始都是有错。如今找到了在 自己机器上成功连接的代码:

1. mysql

Class.forName("com.mysql.jdbc.Driver").newInstance();

String url="jdbc:mysql://localhost:3306/website?characterEncoding=utf8";//website为数据库名。读取mysql中中文字符

String user="root";//登录mysql的username和password

String pwd="123456";

con=DriverManager.getConnection(url,user,pwd);


2. sql server2008
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();

String url="jdbc:sqlserver://localhost:1433;DatabaseName=website";   

String user="sa";//登录sql server的username和password

String pwd="123456";

con=DriverManager.getConnection(url,user,pwd);


原文地址:https://www.cnblogs.com/liguangsunls/p/7259856.html