1、Java连接mysql数据库代码
Class.forName("com.mysql.jdbc.Driver").newInstance();
Stringurl="jdbc:mysql://localhost:3306/website?characterEncoding=utf8";//website为数据库名;读取mysql中中文字符
Stringuser="root";//登录mysql的用户名和密码
Stringpwd="xuebuyuan.com";
con=DriverManager.getConnection(url,user,pwd);
2、java连接sqlserver2008代码
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Stringurl="jdbc:sqlserver://localhost:1433;DatabaseName=website";
Stringuser="sa";//登录sqlserver的用户名和密码
Stringpwd="xuebuyuan.com";
con=DriverManager.getConnection(url,user,pwd);