[Notes database] XML / JASON

JDBC(Java Database Connectivity: Java API to connect and execute the query with the database)

 

import java.sql.*;

    Connection conn= DriverManager.getConnection(…);
    Statement s = conn.createStatement();
    intsid= 5;
    String name = "Jim";
    s.executeUpdate("INSERT INTO STUDENT VALUES(" + sid+ ", '" + name + "')");
    // or equivalently
    s.executeUpdate(" INSERT INTO STUDENT VALUES(5, 'Jim')");
    

As can be directly used to import a IDE the API, to update STUDENTS table. But SQL is a set oriented it returns relations, many programming languages ​​do not support direct output relations of

So, when output only

ResultSet rs = stmt.executeQuery("SELECT * FROM STUDENT");
while (rs.next()) {
  int sid = rs.getInt("sid");
  String name = rs.getString("name");
  System.out.println(sid + ": " + name);
}

This query is obviously very time-consuming

So, we can improve with PreparedStatement

PreparedStatementstmt = conn.prepareStatement("SELECT * " +"FROM STUDENT WHERE sid= ? ");
int[] students = {1, 2, 4, 7, 9};
for (inti= 0; i< students.length; ++i) {
    stmt.setInt(1, students[i]);
    ResultSetrs= stmt.executeQuery();
    while (rs.next()) {…}

So there are still a lot of security problems, and can not avoid end user input illegal characters.

 

                                 

JSON: A data exchange format

 

JSON value

  • digital
  • String: ""
  • A Boolean value: true / false
  • Array: [] 
  • Object: {}
  • null

 

Nearly all programming languages ​​have JSON parsing library

  • Using JSON in JavaScript
var myObject= eval('(' + myJSONtext+ ')');
var myObject= JSON.parse(myJSONtext);
  • Using JSON in XmlHttpRequest
xmlhttp.setRequestHeader(
'Content-type',
'application/x-www-form-urlencoded;charset=UTF-8;'
);
xmlhttp.send('jsondata=' + escape(myJSONText));  // 将JSON文件传给server
  • Using JSON in java
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
……
public class MyServletextends HttpServlet{
public void doGet(HttpServletRequestrequest,HttpServletResponseresponse) throws ServletException, IOException
{
    response.setContentType("text/html");
    PrintWriterout = response.getWriter();
    String feedURLString= request.getParameter("feedURL");
    String script ="";
    JSONObjectobj= new JSONObject();
    JSONArrayarry= new JSONArray();
……
}

 

                                   

XML: Extensible Markup Language Extensible Markup Language

                                       | | ___ is not a programming language, because they can not compute and implement algorithms can only save data

                                       | ____ markup with the label to ensure that both human-readable and machine-readable

 

Converted to XML Data Model: 

 

 

 

Guess you like

Origin www.cnblogs.com/liuliu5151/p/10982900.html