Java network programming, database programming, XML parsing technology.

Source: Internet
Author: User
Tags cdata stmt xml parser

Java Network programming

Physical layer.

Data link layer.

Network layer.

Transport layer.

Session layer.

The presentation layer.

Application layer.

The TCP/IP layered interface includes the following functions for the collaboration layer, respectively:

The network interface layer.

Network interconnect layer.

Transport layer.

Application layer.

Socket:

Socket. Sockets. is an abstraction layer.

//Create a client socket to initiate a connection request to the serverSocket socket =NewSocket ("127.0.0.1", 30001); /*Create an input-output stream with an established socket to handle connections to the server side*/        //writing data to the serverBufferedWriter writer =NewBufferedWriter (NewOutputStreamWriter (Socket.getoutputstream ())); Writer.write ("Hello server!!!");        Writer.flush (); //read data from the serverBufferedReader reader =NewBufferedReader (NewInputStreamReader (Socket.getinputstream ())); Char[] ch =New Char[100]; intLen =reader.read (CH); System.out.println ("Information received from the server side:"); System.out.print (NewString (CH, 0, Len)); //Freeing ResourcesReader.close ();        Writer.close (); Socket.close ();

Database programming

JDBC is a set of database programming APIs available in Java.

The DriverManager class is used to manage the JDBC-driven service classes.

The connection interface represents a database connection.

The statement interface represents the SQL statement.

The ResultSet interface represents the returned result set.

Connection conn =NULL;//Connection ObjectStatement stmt =NULL;//Statement ObjectResultSet rs =NULL;//Query Result set        /*Load Driver*/        Try{class.forname ("Com.mysql.jdbc.Driver"); } Catch(ClassNotFoundException e) {e.printstacktrace (); }        /*Create a Connection object*/        //Connection StringString url = "Jdbc:mysql://localhost:3306/java"; //User nameString user = "root"; //PasswordString pwd = "5245"; Try {            //Create a connectionconn =drivermanager.getconnection (URL, user, pwd); System.out.println ("Connection succeeded"); } Catch(SQLException e) {e.printstacktrace (); }        /*Create a statement object*/        Try{stmt=conn.createstatement (); } Catch(SQLException e) {e.printstacktrace (); }        /*send SQL statement execution*/         //Add//String SQL1 =//INSERT into Users (ID,USERNAME,PWD) VALUES (4, ' HXS ', ' 1995 ');//int count = 0;//try {//count = stmt.executeupdate (SQL1);//} catch (SQLException e) {//         //e.printstacktrace ();//         }/// * Process Execution Results * ///if (count = = 1) {//System.out.println ("add Success");//} else {//System.out.println ("Add failed");//         }        //EnquiryString sql = "SELECT ID, username, pwd from users"; Try {            //get query result setrs =stmt.executequery (SQL); } Catch(SQLException e) {//e.printstacktrace ();        }        Try {            //Loop through the next record             while(Rs.next ()) {//get a column value in a rowSYSTEM.OUT.PRINTLN ("id =" + rs.getint ("id") + ", username =" + rs.getstring ("username") + ", pass Word = "+ rs.getstring (" pwd ")); }        } Catch(SQLException e) {//e.printstacktrace ();        }        /*freeing resources: Must-do*/        if(Conn! =NULL)            Try{conn.close (); } Catch(SQLException e) {e.printstacktrace (); } finally {                if(rs! =NULL)                    Try{rs.close (); } Catch(SQLException e) {e.printstacktrace (); } finally {                        if(stmt! =NULL)                            Try{stmt.close (); } Catch(SQLException e) {e.printstacktrace (); }                        }                }        }

XML parsing Technology

XML: Extensible Markup Language.

Form:

Validated processors-check the validity and format specifications of the XML document.

Processor without validation--check the format specification of the XML document.

The XML parser uses two basic APIs:

Document Object Model (DOM): An API based on tree structure.

XML Simple API (SAX): An event-driven API.

<!--Penguin--><penguins>    <penguin id= "1" >        <name> peas </name>    <!--name--        <close>100</close>        <!--intimacy values    --
<! ELEMENT Pet (dogs,penguins) ><! ELEMENT Dogs (dog*) ><! ELEMENT Dog (name,close,health,breed) ><! Attlist Dog ID CDATA #REQUIRED ><! ELEMENT Penguins (penguin*) ><! ELEMENT Penguin (Name,close,health,gender) ><! attlist Penguin ID CDATA #REQUIRED ><! ELEMENT name (#PCDATA) ><! ELEMENT Close (#PCDATA) ><! ELEMENT Health (#PCDATA) ><! ELEMENT Breed (#PCDATA) ><! ELEMENT gender (#PCDATA) >

Java network programming, database programming, XML parsing technology.

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.