Home  >  Article  >  Database  >  java连接mysql和sqlserver2008代码_MySQL

java连接mysql和sqlserver2008代码_MySQL

WBOY
WBOYOriginal
2016-06-01 13:01:081001browse

这两天用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的用户名和密码

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的用户名和密码

String pwd="123456";

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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn