Java reads the interface data and saves it to the database __java&javaweb

Source: Internet
Author: User
The table structure of the public class test05getdata {//guo sheng shi xian zhen cun is exactly the same.
	After all the data has been read, the data is consolidated into the same table protected static string parenttable =  "Sheng";//  parent table protected static string inserttable =  "Shi";//  Word table protected static  string daima =  "";//  code protected static int datacount = 0;//   Counter protected static int totaldata = 0;//  Total records of the parent table protected static 
	connection connection = null;
	protected static statement statement = null;

	protected static resultset resultset = null; Public static void main (String[] args)  {connection = 
		Dbconnection.getoracleconnection ();
		statement = null;
		resultset = null;
		List<string>list = new arraylist<string> (); Try&nBsp
			{statement = connection.createstatement ();
			Resultset = statement.executequery ("select * from "  + parenttable);
				while  (Resultset.next ())  {totaldata ++;
				Daima = resultset.getstring ("Daima");
			List.add (Daima);
		} System.out.println ("Tataldata:"  + totaldata);
		} catch  (exception e)  {e.printstacktrace (); } for  (Iterator iterator = list.iterator ();  iterator.hasnext ();)  {String 
			string =  (String)  iterator.next ();
			datacount ++;
			double x1 =  (Double) datacount/(double) totaldata) *100.0 ;
			System.out.print ("First"  + dataCount +  "parent");			
		System.out.println (String.Format ("%.2f",  x1)  +  "%");//Show Percent complete query (String);
			} try {if  (resultset != null)  {resultset.close (); } if  (statement != null)  {statement.close ();
			} if (Connection != null) {connection.close ();
		}} catch  (Exception e)  {e.printstacktrace (); } public static void query (String daima)  {string url =  "http://
		Api.dangqian.com/apidiqu2/api.asp?id= " + daima;
		Stringbuilder stringbuilder = new stringbuilder ();
		url oracle;
			try {Oracle = new url (URL);
			Urlconnection yc = oracle.openconnection ();
			Bufferedreader br = new bufferedreader (New inputstreamreader (Yc.getInputStream ()));
			string inputline = null;
			while  ((Inputline = br.readline ())  != null)  {stringbuilder.append (inputLine);
			} br.close ();
			String str = stringbuilder.tostring ();
			Stringbuffer stringbuffer = new stringbuffer (str); StringBuffer. Delete (0, 9);
			Stringbuffer.deletecharat (Stringbuffer.length ()  - 1);
			System.out.println (StringBuffer);
			Jsonobject jsonobject = jsonobject.fromobject (Stringbuffer.tostring ());
			jsonobject jsonobject1 =  (Jsonobject)  jsonobject.get ("list");
			 system.out.println (JSONOBJECT1);
			List<shi> list = new arraylist<shi> (); for  (Iterator iter = jsonobject1.keys ();  iter.hasnext ();)  {String key 
				=  (String)  iter.next ();
				shi shi =  (Shi)  jsonobject.tobean ((jsonobject)  jsonobject1.get (key),  Shi.class);
			List.add (shi);
		} savedata (list);
		} catch  (exception e)  {e.printstacktrace (); } protected static void savedata (List<shi>list) {//storing the read data to the database string sql =
		  "insert into " + inserttable+ " values (?,?,?,?)"; Shi shi = null;
		Int size = list.size (); try {for  (int i = 0; i < size; i++)  {shi = 
				List.get (i); sql =  "insert into " + inserttable+ "  (Zidi,diming,daima,dengji) VALUES (" +
				Shi.getzidi () + ", '" +shi.getdiming () + "', '" +shi.getdaima () + "'," +shi.getdengji () + ")";
			Statement.execute (SQL);
		}} catch  (Exception e)  {e.printstacktrace (); }
		
	}

}

http://api.dangqian.com/apidiqu2/api.asp?id=420000000000

The data returned is as follows

Callback ({  "Is_login":1,  "site": "China administrative division API",  "url": "Http://api.dangqian.com/apidiqu2/",  " Jieshao ":" "Provincial and municipal county level five administrative divisions address information database",  "Idengji": "2",  "idiming": "Hubei",  "Idaima": "420000000000",  " Diming1 ":" "China",  "daima1": "000000000000",  "diming2": "Hubei Province",  "Daima2": "420000000000",  "Diming3" ":" ", " daima3 ":" ", " Diming4 ":",  "DAIMA4": "",  "Diming5": "",  "Daima5": "",  " Diming6 ":" ", " Daima6 ":" ", " Zidi ":14, " Banben ":" The,  "Zhizao": "Wang Jianjan",  "QQ": "250247045 ", " Riqi: "2013-4-21 16:08:25",  "Shike": "2014-8-25 9:29:46",  "id": "",  "list": {   "WJR1": {"Dengji": "3", "diming": "Wuhan City", "Daima": "420100000000", "Zidi":13},  "WJR2": {"Dengji": "3", "diming ":" Huangshi "," Daima ":" 420200000000 "," Zidi ":6}, " Wjr3 ": {" Dengji ":" 3 "," diming ":" Shiyan "," Daima ":" 420300000000 "," Zidi ":8}, " Wjr4 ": {" Dengji ":" 3 "," diming ":" Yichang "," Daima ":" 420500000000 "," Zidi ":13}, " WJR5 ": {" Dengji ":" 3 "," diming ":" Xiangyang City "," Daima ": "420600000000", "Zidi":9},  "WJR6": {"Dengji": "3", "diming": "Ezhou", "Daima": "420700000000", "Zidi":3},  " Wjr7 ": {Dengji": "3", "diming": "Jingmen", "Daima": "420800000000", "Zidi":5},  "wjr8": {"Dengji": "3", "diming": "Xiaogan", "Daima": "420900000000", "Zidi":7},  "Wjr9": {"Dengji": "3", "diming": "Jinzhou", "Daima": "421000000000", "Zidi": 8},   "Wjr10": {"Dengji": "3", "diming": "Huanggang", "Daima": "421100000000", "Zidi":10},  "Wjr11": {"Dengji": "3", " Diming ":" Xianning "," Daima ":" 421200000000 "," Zidi ":6}, " Wjr12 ": {" Dengji ":" 3 "," diming ":" Suizhou "," Daima ":" 421300000000 "," Zidi ":3}, " Wjr13 ": {" Dengji ":" 3 "," diming ":" Enshi "," Daima ":" 422800000000 "," Zidi ": 8},   "Wjr14": {"Dengji": "3", "diming": "Prefecture-level administrative division", "Daima": "429000000000", "Zidi": 4} } })

You only need to parse out the list part to store it in the database.

The above content is only for technical sharing, and any legal issues related to me and 51cto are irrelevant. Please do not use for commercial purposes.

This article from the "Excellent Game Studio" blog, please be sure to keep this source http://shamrock.blog.51cto.com/2079212/1544270

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.