在往数据库的表中写入数据时,一定要与表中的每一项对应,比如表中有三项,则写入的值也应该是三类:

1 String getTitle=request.getParameter("title");   
2 String getContent=request.getParameter("message");  
3 java.text.SimpleDateFormat time = new java.text.SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");  
4 String sql = "INSERT INTO message(title, content, time) VALUES ('"+getTitle+"', '"+getContent+"', ' "+time.format(new java.util.Date())+"')";  

 

在往数据库中要写入中文时,要注意所有的格式都应该是utf-8,此外还应在链接数据库时加入:

1 String url="jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=UTF-8";

 

posted on 2017-07-03 08:38  yanxi1900  阅读(137)  评论(0编辑  收藏  举报