完美解决 Date 对象存入mysql数据库

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_40969108/article/details/85254288

笔者是在jsp页面存入数据到数据库时遇到的这个问题,现在记录下来,供大家参考

1 在jsp页面中设置input的类型为date类型:

在servlet中获取date

 或者使用

 

展开阅读全文

存入mysql数据库

09-25

package com.tb.action;rnrnimport java.io.BufferedReader; rnimport java.io.IOException; rnimport java.io.InputStreamReader; rnimport java.net.MalformedURLException; rnimport java.net.URL; rnimport java.util.ArrayList; rnimport java.util.List; rnimport java.util.regex.Matcher; rnimport java.util.regex.Pattern; rnrnrnimport com.opensymphony.xwork2.ActionSupport;rnimport com.tb.model.test.Test;rnimport com.tb.service.test.TestService;rn rnpublic class TestAction extends ActionSupport rn private static TestService testService;rn public static Test t1=new Test();rn rn public String getHtmlContent(String htmlurl) rn URL url; rn String temp; rn StringBuffer sb = new StringBuffer(); rn try rn url = new URL(htmlurl); rn BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8")); rn while ((temp = in.readLine()) != null) rn sb.append(temp); rn rn in.close(); rn catch (final MalformedURLException me) rn System.out.println("您输入的URL有问题!"); rn me.getMessage(); rn catch (final IOException e) rn e.printStackTrace(); rn rn return sb.toString(); rn rn rn /** rn * rn * @param s rn * @return 获得网页标题 rn */ rn public String getTitle(String s) rn String regex; rn String title = ""; rn List list = new ArrayList(); rn regex = " .*?"; rn Pattern pa = Pattern.compile(regex, Pattern.CANON_EQ); rn Matcher ma = pa.matcher(s); rn while (ma.find()) rn list.add(ma.group()); rn rn for (int i = 0; i < list.size(); i++) rn title = title + list.get(i); rn rn return outTag(title); rn rn rn /** rn * rn * @param s rn * @return 获得链接 rn */ rn public List getLink(String s) rn String regex; rn List list = new ArrayList(); rn regex = "]*href=(\"([^\"]*)\"|\'([^\']*)\'|([^\\s>]*))[^>]*>(.*?)"; rn Pattern pa = Pattern.compile(regex, Pattern.DOTALL); rn Matcher ma = pa.matcher(s); rn while (ma.find()) rn list.add(ma.group()); rn rn return list; rn rn rn /** rn * rn * @param s rn * @return 获得脚本代码 rn */ rn public List getScript(String s) rn String regex; rn List list = new ArrayList(); rn regex = ""; rn Pattern pa = Pattern.compile(regex, Pattern.DOTALL); rn Matcher ma = pa.matcher(s); rn while (ma.find()) rn list.add(ma.group()); rn rn return list; rn rn rn public List getNewsurl(String s) rn String regex = ""; rn rn Pattern pa = Pattern.compile(regex, Pattern.DOTALL); rn Matcher ma = pa.matcher(s); rn List list = new ArrayList(); rn while (ma.find()) rn list.add(ma.group());rn rn rn rn return list; rn rn rn rn /** rn * rn * @param s rn * @return 获得CSSrn */ rn public List getCSS(String s) rn String regex; rn List list = new ArrayList(); rn regex = ""; rn Pattern pa = Pattern.compile(regex, Pattern.DOTALL); rn Matcher ma = pa.matcher(s); rn while (ma.find()) rn list.add(ma.group(1)); rn rn return list; rn rn rn /** rn * rn * @param s rn * @returnrn */ rn public String outTag(final String s) rn return s.replaceAll("<.*?>", ""); rn rn rn rn rn rn public static void main(String[] args) rn TestAction t = new TestAction();rn int i=1;rn String content = t.getHtmlContent("http://www.baidu.com"); rn //content = content.replaceAll("( )+?", "\n");//转化换行 rn //content = content.replaceAll(" .*?", "");// 去图片注释 rn System.out.println(content);rn List a = t.getNewsurl(content);rn List news = new ArrayList(); rn for (String s : a) rn news.add(s.replaceAll("<.*?>", "")); //正则表达式 rn t1.setNews_title(s);rn i++;rn String str=t1.getNews_title();rn Pattern p=Pattern.compile("(.+?)");rn Matcher m=p.matcher(str);rn while(m.find()) rn t1.setNews_title(m.group(1));rn System.out.println(t1.getNews_title());rn t1.setNews_id(i);rn rn rn testService.save(t1);rn rn public static TestService getTestService() rn return testService;rn rn public static void setTestService(TestService testService) rn TestAction.testService = testService;rn rn rn rn怎么将代码取得的数据存入数据库 论坛

没有更多推荐了,返回首页