日期:2014-05-17 浏览次数:20673 次
+--------------------------+---------------------------------------------------- -----+ | Variable_name | Value | +--------------------------+---------------------------------------------------- -----+ | character_set_client | gbk | | character_set_connection | gbk | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | gbk | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | C:\Program Files\MySQL\MySQL Server 5.0\share\charsets\ | +--------------------------+----------------------------------------------------
--------------+ | Table | Create Table | +-------+----------------------------------- -------------------------------------------- -------------------------------------------- -------------------------------------------- --------------+ | boke | CREATE TABLE `boke` ( `id` int(11) NOT NULL auto_increment, `title` varchar(200) collate utf8_bin NOT NULL, `content` longtext collate utf8_bin, `owner` varchar(20) collate utf8_bin NOT NULL, `time` varchar(40) collate utf8_bin NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin | +-------+-----------------------------------
String title=request.getParameter("title"); String mytitle=new String(title.getBytes("ISO-8859-1")); String content=request.getParameter("content"); String mycontent=new String(content.getBytes("ISO-8859-1")); //java.util.Date date=new java.util.Date(); SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = tempDate.format(new java.util.Date());//取当前时间
try{ Class.forName("com.mysql.jdbc.Driver"); String url="jdbc:mysql://localhost/test?user=root&password=1234"; Connection con=DriverManager.getConnection(url); String sql="insert into boke value(0,?,?,?,?)"; PreparedStatement pstmt=con.prepareStatement(sql); pstmt.setString(1,mytitle); pstmt.setString(2,mycontent); pstmt.setString(3,owner); pstmt.setString(4,time); //PreparedStatement pstmt=con.prepareStatement(sql); int m=pstmt.executeUpdate(); pstmt.close(); con.close(); }catch(Exception e){ out.print(e.getMessage()); }