思路:从sqlserver数据库读取网站,然后将实时的行情写入mysql数据库http://hq.sinajs.cn/list=sh601006,假设前面几个字段即可符合要求
1、sqlserver 表create table url(www varchar(100));
insert into url values('http://hq.sinajs.cn/list=')
create table product(code varchar(10),name nvarchar(20));
insert into product values('sh601006','大秦铁路');
insert into product values('sh601001','大同煤业');
create view  v_link
as
select b.www,a.code from product as a  cross join url as b2、mysql 表create table quotdata(
ContractId INT(11),
RisePrice decimal(20,8),
FallPrice decimal(20,8),
OpenPrice decimal(20,8),
NewPrice decimal(20,8),3、java获取的sqlserver的网址
package andyu;
import java.sql.*;
public class connSqlServer {

public static void main(String[] srg) {
    connSqlServer cServer=new connSqlServer();
}
public connSqlServer()
{
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";  //加载JDBC驱动
  String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=SinaQuot";  //连接服务器和数据库test
  String userName = "sa";  //默认用户名
  String userPwd = "123456";  //密码
  @SuppressWarnings("unused")
  Connection dbConn;   try {
   Class.forName(driverName);
   dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
   System.out.println("Connection Successful!");  //如果连接成功 控制台输出Connection Successful!
  Statement s=dbConn.createStatement();
  String selectsql ="select * from v_link";
  ResultSet r=s.executeQuery(selectsql);
    while(r.next())
   {
     System.out.print(r.getString("www")+r.getString("code")+"\n");
     
   }
   } catch (Exception e) {
   e.printStackTrace();
  }
}
}如何写代码,因为要得较急,而我对java不是很熟,特盼高手写出,不胜感激Java数据库URL

解决方案 »

  1.   

    可以了。刚开始就这样写。
    这个是新浪的api
      

  2.   

    但是我想写入mysql 数据库,而且还不会截取字符
      

  3.   

    package andyu;
    import java.io.BufferedReader;  
    import java.io.BufferedWriter;  
    //import java.io.File;  
    //import java.io.FileReader;  
    //import java.io.FileWriter;  
    //import java.io.IOException;  
    //import java.io.InputStreamReader;  
    import java.net.URL;  
    import java.net.URLConnection;  
    //import java.util.ArrayList;  
    //import java.util.Arrays;  
    //import java.util.List;  
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.sql.*;
    public class SinaQuot1 {
    //PreparedStatement ps=null;
    //Connection ct=null;
    //ResultSet rs=null;
    String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";  //加载JDBC驱动
    String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=SinaQuot";  //连接服务器和数据库test
    String userName = "sa";  //默认用户名
    String userPwd = "123!@#qweQWE";  //密码
    Connection dbConn;
    String text=null;
    StringBuffer sb=new StringBuffer();

    public static void main(String args[]){
    SinaQuot1 sq1=new SinaQuot1();
    }
    public SinaQuot1()
    {
    try{Class.forName(driverName);
       dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
       System.out.println("Connection Successful!");  //如果连接成功 控制台输出Connection Successful!
      Statement s=dbConn.createStatement();
      String selectsql ="select * from v_link";
      ResultSet r=s.executeQuery(selectsql);
      StringBuffer sb=new StringBuffer();
         try {
    URL readSource = new URL("http://hq.sinajs.cn/list=sh601001");
    BufferedReader input = new BufferedReader(new InputStreamReader(readSource.openStream()));
    String line;

    while((line = input.readLine()) !=null){
    sb.append(line);
    }
    System.out.println(sb.toString());
         } catch (Exception e) {
    e.printStackTrace();
         }
      
      
         while(r.next())
        {
     text=r.getString("www")+r.getString("code");
         System.out.print(text+"\n");
         
       }
      }catch(Exception e) {
      e.printStackTrace();
       }finally{
       
       }


    }
    }
    我暂时还只会到这里 获取字符
      

  4.   

    你把url请求到的数据json的key转换一个实体bean的属性。根据映射建表。这样入库就是简单的bean的属性映射了
      

  5.   

    var hq_str_sh601006="大秦铁路,7.08,7.08,7.06,7.08,7.05,7.05,7.06,2013907,14229810,795171,7.05,232900,7.04,304700,7.03,373200,7.02,90500,7.01,82594,7.06,156208,7.07,98740,7.08,35900,7.09,107400,7.10,2013-06-04,09:51:30,00";
    新浪这样做就是不想别人看他行情的具体属性。哈哈
      

  6.   

    给你看一个行情beanpublic class TStQuote { private String advstop = "--";
    private String amount = "--";
    private String avgvolume = "--";
    private List buyprice = null;
    private List buyvolume = null;
    private String decstop = "--";
    private String high = "--";
    private String inner = "--";
    private String lastclose = "--";
    private String low = "--";
    private String newprice = "--";
    private String nowvol = "--";
    private String obj = "--";
    private String open = "--";
    private String outter = "--";
    private List sellprice = null;
    private List sellvolume = null;
    private String settleprice = "--";
    private String tickcount = "--";
    private String time = "--";
    private String volume = "--"; public TStQuote() {
    } public TStQuote(String advstop, String amount, String avgvolume,
    List buyprice, List buyvolume, String decstop, String high,
    String inner, String lastclose, String low, String newprice,
    String nowvol, String obj, String open, String outter,
    List sellprice, List sellvolume, String settleprice,
    String tickcount, String time, String volume) {
    super();
    this.advstop = "".equals(advstop) ? "--" : advstop;
    this.amount = "".equals(amount) ? "--" : amount;
    this.avgvolume = "".equals(avgvolume) ? "--" : avgvolume;
    this.buyprice = buyprice;
    this.buyvolume = buyvolume;
    this.decstop = "".equals(decstop) ? "--" : decstop;
    this.high = "".equals(high) ? "--" : high;
    this.inner = "".equals(inner) ? "--" : inner;
    this.lastclose = "".equals(lastclose) ? "--" : lastclose;
    this.low = "".equals(low) ? "--" : low;
    this.newprice = "".equals(newprice) ? "--" : newprice;
    this.nowvol = "".equals(nowvol) ? "--" : nowvol;
    this.obj = "".equals(obj) ? "--" : obj;
    this.open = "".equals(open) ? "--" : open;
    this.outter = "".equals(outter) ? "--" : outter;
    this.sellprice = sellprice;
    this.sellvolume = sellvolume;
    this.settleprice = settleprice;
    this.tickcount = "".equals(tickcount) ? "--" : tickcount;
    this.time = "".equals(time)?new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) : time;
    this.volume = "".equals(volume) ? "--" : volume;
    } public String getAdvstop() {
    return advstop;
    } public void setAdvstop(String advstop) {
    this.advstop = advstop;
    } public String getAmount() {
    return amount;
    } public void setAmount(String amount) {
    this.amount = amount;
    } public String getAvgvolume() {
    return avgvolume;
    } public void setAvgvolume(String avgvolume) {
    this.avgvolume = avgvolume;
    } public List getBuyprice() {
    return buyprice;
    } public void setBuyprice(List buyprice) {
    this.buyprice = buyprice;
    } public List getBuyvolume() {
    return buyvolume;
    } public void setBuyvolume(List buyvolume) {
    this.buyvolume = buyvolume;
    } public String getDecstop() {
    return decstop;
    } public void setDecstop(String decstop) {
    this.decstop = decstop;
    } public String getHigh() {
    return high;
    } public void setHigh(String high) {
    this.high = high;
    } public String getInner() {
    return inner;
    } public void setInner(String inner) {
    this.inner = inner;
    } public String getLastclose() {
    return lastclose;
    } public void setLastclose(String lastclose) {
    this.lastclose = lastclose;
    } public String getLow() {
    return low;
    } public void setLow(String low) {
    this.low = low;
    } public String getNewprice() {
    return newprice;
    } public void setNewprice(String newprice) {
    this.newprice = newprice;
    } public String getNowvol() {
    return nowvol;
    } public void setNowvol(String nowvol) {
    this.nowvol = nowvol;
    } public String getObj() {
    return obj;
    } public void setObj(String obj) {
    this.obj = obj;
    } public String getOpen() {
    return open;
    } public void setOpen(String open) {
    this.open = open;
    } public String getOutter() {
    return outter;
    } public void setOutter(String outter) {
    this.outter = outter;
    } public List getSellprice() {
    return sellprice;
    } public void setSellprice(List sellprice) {
    this.sellprice = sellprice;
    } public List getSellvolume() {
    return sellvolume;
    } public void setSellvolume(List sellvolume) {
    this.sellvolume = sellvolume;
    } public String getSettleprice() {
    return settleprice;
    } public void setSettleprice(String settleprice) {
    this.settleprice = settleprice;
    } public String getTickcount() {
    return tickcount;
    } public void setTickcount(String tickcount) {
    this.tickcount = tickcount;
    } public String getTime() {
    return time;
    } public void setTime(String time) {
    this.time = time;
    } public String getVolume() {
    return volume;
    } public void setVolume(String volume) {
    this.volume = volume;
    } @Override
    public String toString() {
    return "TStQuote [advstop=" + advstop + ", amount=" + amount
    + ", avgvolume=" + avgvolume + ", buyprice=" + buyprice
    + ", buyvolume=" + buyvolume + ", decstop=" + decstop
    + ", high=" + high + ", inner=" + inner + ", lastclose="
    + lastclose + ", low=" + low + ", newprice=" + newprice
    + ", nowvol=" + nowvol + ", obj=" + obj + ", open=" + open
    + ", outter=" + outter + ", sellprice=" + sellprice
    + ", sellvolume=" + sellvolume + ", settleprice=" + settleprice
    + ", tickcount=" + tickcount + ", time=" + time + ", volume="
    + volume + "]";
    }}