Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » MySQL  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 用java把抓取的网页代码保存到MYSQL的问题
txwd007





发贴: 2
积分: 0
于 2006-06-30 00:00 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import java.net.*;
import java.io.*;
import java.lang.*;
import java.sql.*;

public class Openinto
{
  public String getContent(String strUrl)
    // 一个public方法,返回字符串,错误则返回error open url
  {
    StringBuffer sb=new StringBuffer();
    try{

       URL url=new URL(strUrl);
      BufferedReader br=new BufferedReader(new InputStreamReader(url.openStream()));
      String s=br.readLine();
      
      while((s=br.readLine())!=null){
        sb.appendMoon;
       }
      br.close();
      
    } catch(Exception e) {
// return error open url + strUrl;
      e.printStackTrace();
    }
    return sb.toString();
  }

  public static void main(String args[])
  {

    String web = "http://www.21cn.com";
    Openinto ou=new Openinto();
   String yes = ou.getContent(web);
  
  //intojdbc
   try{
    String driverName = "org.gjt.mm.mysql.Driver";
      String dbpath = "jdbc:mysql://localhost/gray";
      String username = "root";
      String password = "gemini0527";
      String sql3 = "insert into person values(?,?)";
      String id = "www.21cn.com";
     String name = yes;
     Class.forName(driverName);
      Connection conn = DriverManager.getConnection(dbpath,username,password);
      PreparedStatement pstmt = conn.prepareStatement(sql3);
      pstmt.setString(1,id);
      pstmt.setString(2,name);
      pstmt.executeUpdate();
      pstmt.close();
      conn.close();
   }catch(SQLException sqe) {
         System.out.println("SQL Error:" + sqe.getMessage());
       }catch(ClassNotFoundException cnfe) {
         System.out.println(cnfe.getMessage());
       }
   }
}
出现的错误是:
SQL Error: Data truncation: Data too long for column 'name' at row 1
我的数据库(id[char];name[txet]);
我把name的类型改的text,但是还是出现这个错误~~ -_-!
本人菜鸟一个,在此求教了!



作者 Re:用java把抓取的网页代码保存到MYSQL的问题 [Re:txwd007]
txwd007





发贴: 2
积分: 0
于 2006-07-02 23:00 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
SuN034呵呵~~把name 改成 longtxet类型就行~~~~
楼主sb一个!



作者 Re:用java把抓取的网页代码保存到MYSQL的问题 [Re:txwd007]
zcjl

涅槃



发贴: 537
积分: 65
于 2006-07-02 23:46 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
txwd007 wrote:
SuN034呵呵~~把name 改成 longtxet类型就行~~~~
楼主sb一个!

who's "楼主" here?
and "sb" for SuperBoy? Smile




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923