Home > Database > Mysql Tutorial > body text

java连接mysql和sqlserver2008代码_MySQL

WBOY
Release: 2016-06-01 13:01:08
Original
1047 people have browsed it

这两天用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);


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template