Java uses JDBC Connection database to do JSON encapsulation and parsing examples
This example is an example of using SOLServer2007 to connect a database with JDBC and to query the data format encapsulated into JSON.
Directly on the code--
Main function
Package Com.kuatang.jsondatas;
public static final String jsonshellbefor = "{";
public static final String jsonshellafter = "}";
public static final String Jsonlink = ":";
public static final String jsoninterval = ",";
public static final String Jsonstringsymbol = "\";
public static void Main (String args[]) {
/**
* JSON data encapsulation output, completed connection database query data
*/
JSON JSON = new JSON ();
Json. JSONOJECTSTR ()//test passed
Getjsondata ()//The JSON wrapper test with no database query passed
Getjsoncontent (1281, "66.3gp");/test Passed
/**
* Test the correctness of IP, through
*/
Isrightip ("192.168.1.101");
SYSTEM.OUT.PRINTLN ("-----------------*-----------------");
Isrightip ("11.168.1.101");
SYSTEM.OUT.PRINTLN ("-----------------* *-----------------");
Isrightip ("101");
SYSTEM.OUT.PRINTLN ("-----------------* * * *-----------------");
/**
* Test IP + port test pass
*/
Isrightipandport ("192.168.1.101");
System.out.println ("*************************************");
Isrightipandport ("192.168.1.101.6666");
System.out.println ("*************************************");
Isrightipandport ("192.168.1.101:7887");
System.out.println ("*************************************");
/**
* ID3 algorithm, decision tree test through
*/
ID3 Inst = new ID3 ();
Inst.readarff (New File ("E:\\myeclipse 2014\\id3_arff.txt"));
Inst.setdec ("Play");//string with play, because the combination of text, determine the calculation of the entropy of the positive and negative examples Yes and no
Linkedlist<integer> ll=new linkedlist<integer> ();
//
for (int i=0;i<inst.attribute.size (); i++) {
if (I!=inst.decatt)
Ll.add (i);
// }
Arraylist<integer> al=new arraylist<integer> ();
for (int i=0;i<inst.data.size (); i++) {
Al.add (i);
// }
INST.BUILDDT ("DecisionTree", "null", AL, LL);
Inst.writexml ("E:\\dtid3.xml");
}
public static Boolean Isrightip (String arg0) {
Regular expression: IP address
String Ipregex = "\\b (?! \\d\\d\\d) \\d+|1\\d\\d|2[0-4]\\d|25[0-5]) \. ((?! \\d\\d\\d) \\d+|1\\d\\d|2[0-4]\\d|25[0-5]) \. ((?! \\d\\d\\d) \\d+|1\\d\\d|2[0-4]\\d|25[0-5]) \. ((?! \\d\\d\\d) \\d+|1\\d\\d|2[0-4]\\d|25[0-5]) \\b ";
Pattern pattern = pattern.compile (Ipregex);
String s = "255.255.255.255";
Matcher Matcher = Pattern.matcher (arg0);
if (Matcher.matches ()) {
System.out.println (arg0 + "is the correct IP address.) ");
return true;
}
else{
System.out.println (arg0 + "is not the correct IP address.) ");
return false;
}
}
/*----------------------------------------------------------------------*/
public static Boolean Isrightipandport (String arg0) {
Regular expression: IP address + port number
String Ipandportregex = "\\b (?! \\d\\d\\d) \\d+|1\\d\\d|2[0-4]\\d|25[0-5]) \. ((?! \\d\\d\\d) \\d+|1\\d\\d|2[0-4]\\d|25[0-5]) \. ((?! \\d\\d\\d) \\d+|1\\d\\d|2[0-4]\\d|25[0-5]) \. ((?! \\d\\d\\d) \\d+|1\\d\\d|2[0-4]\\d|25[0-5]) \\:\\d{1,5}\\b ";
Pattern pattern = pattern.compile (Ipandportregex);
Matcher Matcher = Pattern.matcher (arg0);
if (Matcher.matches ()) {
System.out.println (arg0 +) is the correct ip+ port number address. ");
return true;
}
else{
System.out.println (arg0 +) is not the correct ip+ port number address. ");
return false;
}
}
public static String Getjsondata () {
String buffer = new string ();
String strbuffer = new string ();
Class.forName (Qu_dong);
conn = Drivermanager.getconnection (URL);
State = Conn.createstatement ();
rs = State.executequery (SQL);
Getting metadata for a result set
ResultSetMetaData RSMD = Rs.getmetadata ();
int datasize = Rsmd.getcolumncount ();
while (Rs.next ()) {
}
————————————————————————————————————————————————————————————————————————————————————————
The corresponding jar pack please go to my csdn resources to download.
————————————————————————————————————————————————————————————————————————————————————-
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.