package com.connect;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class connect {
//private String Uri = "jdbc:mysql://w.rdc.sae.sina.com.cn:3307/app_classmatealu?useUnicode=true&characterEncoding=utf-8";
//private String User = "kzw4wxk145";
//private String Pass = "ih1mj24ywlhjwwiiyiw1ljzxh5jkim00h32zjxwi";
private String Uri = "jdbc:mysql://localhost:3306/coursedesign?characterEncoding=UTF-8";
private String User = "root";
private String Pass = "1412190414";
private String driver="com.mysql.jdbc.Driver";
private Connection con;
private Statement stmt;
public Connection con(){
try{
Class.forName(driver);
con = DriverManager.getConnection(Uri,User,Pass);
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS user (" +
"id int not null primary key auto_increment," +
"UserNumber CHAR(20)," +
"UserPassword CHAR(15),"+
"Time CHAR(10))charset utf8 collate utf8_general_ci");
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS message (" +
"id int not null primary key auto_increment," +
"UserNumber CHAR(20)," +
"ToUserNumber CHAR(20),"+
"UserName CHAR(20),"+
"ToUserName CHAR(20),"+
"Content CHAR(100),"+
"Time CHAR(10))charset utf8 collate utf8_general_ci");
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS person (" +
"UserNumber CHAR(20)," +
"UserName CHAR(20),"+
"UserSex CHAR(5),"+
"Birthdate CHAR(20),"+
"Zodiac CHAR(20),"+
"UserPhone CHAR(11),"+
"UserEmail CHAR(20),"+
"University CHAR(20),"+
"Fication CHAR(30),"+
"Time CHAR(10))charset utf8 collate utf8_general_ci");
}
catch(SQLException e){
e.printStackTrace();
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
}
一键复制
编辑
Web IDE
原始数据
按行查看
历史