[Database Notes] XML/JASON

Keywords: PHP JSON xml Javascript Java

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')");
    

                                          

JSON: (JavaScript Object Notation, JS Object Markup), it is a data exchange format.

Before JSON came into being, people used XML to transfer data. Because XML is a plain text format, it is suitable for exchanging data over the network. XML itself is not complicated, but with DTD, XSD, XPath, XSLT and a lot of other complex specifications, any normal software developer will feel headache when encountering XML. Finally, you find that even if you work hard for several months, you may not be able to understand the specifications of XML. Finally, one day in 2002, Douglas Crockford invented JSON, an ultra-lightweight data exchange format, in order to save software engineers who had been fooled by several large software companies for a long time. Because of its simplicity, JSON soon became popular in the Web world and became an ECMA standard. Almost all programming languages have libraries for parsing JSON, but in JavaScript, we can use JSON directly because JavaScript has built-in JSON parsing. To turn any JavaScript object into a JSON is to serialize the object into a JSON-formatted string so that it can be passed over the network to other computers. If we receive a string in JSON format, we can use it directly in JavaScript by deserializing it into a JavaScript object.

An objectis an unordered set of name/value pairs:

{ "name": "html", "years": 5 }

An arrayis an ordered collection of values

[ "html", "xml", "css" ]

 

JSON value

Numbers (integers/floating-point numbers)
String (double quotation marks)
Boolean value (true/false)
Array (in middle brackets)
Object (in braces)
null

 

Almost all programming languages have libraries for parsing JSON

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));  // Pass JSON file to 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

||_ Not programming language, because you can't compute and implement algorithms, only save data

|__ markup uses label to ensure both human-readable and machine-readable

<message>
   <text>Hello, world!</text>
</message>

 

XML Syntax

The following code is an example:

<?xml version = "1.0"?>   // XML declaration: Starting with xml, tells the computer to start reading XML files
<contact-info> 
   <name>Tanmay Patil</name>
   <company>TutorialsPoint</company>
   <phone>(011) 123-4567</phone>
</contact-info>

Posted by ramonekalsaw on Wed, 05 Jun 2019 16:07:13 -0700