关于MYSQL与SQL2005/2008数据库的问题
是这样的,我在网上下了一个博客系统的代码,非常全面,但里面是MYSQL和Myeclipse6.5数据库连接的,但我想让SQL2005和Myeclipse6.5连接,我有MYSQL的创建数据库的代码,发上来给大家看下,能不能改一改,变成SQL2005或2008能用呢。(我的配置是win7|MyEclipse6.5|Tomcat5.5|SQL2005/2008)
以下代码是用记事本打开的:
/*
SQLyog 企业版 - MySQL GUI v7.14
MySQL - 5.1.33-community : Database - blog
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`blog` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `blog`;
/*Table structure for table `blogs` */
DROP TABLE IF EXISTS `blogs`;
CREATE TABLE `blogs` (
`blogid` int(11) NOT NULL,
`title` varchar(50) DEFAULT NULL,
`pubtime` date DEFAULT NULL,
`authorid` int(11) DEFAULT NULL,
`replies` varchar(1000) DEFAULT NULL,
`tbs` int(11) DEFAULT NULL,
`views` int(11) DEFAULT NULL,
`category` int(3) DEFAULT NULL,
`content` varchar(2000) DEFAULT NULL,
`property` int(1) DEFAULT NULL,
PRIMARY KEY (`blogid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*Data for the table `blogs` */
/*Table structure for table `register` */
DROP TABLE IF EXISTS `register`;
CREATE TABLE `register` (
`userid` int(11) NOT NULL,
`username` varchar(11) DEFAULT NULL,
`userpwd` varchar(11) DEFAULT NULL,
`regtime` date DEFAULT NULL,
`usergroup` int(2) DEFAULT NULL,
`email` varchar(20) DEFAULT NULL,
PRIMARY KEY (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*Data for the table `register` */
/*Table structure for table `user` */
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`userid` int(11) NOT NULL,
`nicheng` varchar(11) DEFAULT NULL,
`username` varchar(11) DEFAULT NULL,
`password` varchar(11) DEFAULT NULL,
PRIMARY KEY (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*Data for the table `user` */
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
这是MyEclipse中连接数据库的代码:
package db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBbean {
String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://localhost:1433;databasename=blog_db";
String username="sa";
String password="wangjun";
public Connection con;
public DBbean(){
try {
Class.forName(driver);
con=DriverManager.getConnection(url,username,password);
}
catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
MySQL sql2005 数据库 MyEclipse 博客
[解决办法]
--sql server 2008
IF EXISTS (SELECT * FROM SYS.TABLES WHERE NAME ='user')
begin
drop table user;
end
--sql server 2000
IF EXISTS (SELECT * FROM SYSobjects WHERE NAME ='user' and xtype= 'T')
begin
drop table user;
end