summary on DB_logging_handle

1.two comments on mysql.

drop table in Mysql database:

DROP   TABLE   IF   EXISTS  table_name;

 

create table in Mysql database:

CREATE   TABLE  table_name(
 id 
INT   NOT   NULL  AUTO_INCREMENT  PRIMARY   KEY ,
 column1 
VARCHAR ( 256 ),
 column2 
DECIMAL ( 6 ),
 column3 
TEXT ,
 column4 
BIGINT
);


2.Read .properties and .xml files by java
2.1 read .xml files
(copy from http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html)
This sample code reads the XML file using DOM parser. DOM parser loads the XML file into
the memory and makes an object model of it. This Object modal can be traversed to get
its elements.
this is test.xml which is in test_files fold

xml version="1.0" ?>
< company >
 
< employee >
  
< firstname > Tom firstname >
  
< lastname > Cruise lastname >
 
employee >
 
< employee >
  
< firstname > Paul firstname >
  
< lastname > Enderson lastname >
 
employee >
 
< employee >
  
< firstname > George firstname >
  
< lastname > Bush lastname >
 
employee >
company >

 

 

package  readfile;

import  java.io.File;

import  javax.xml.parsers.DocumentBuilder;
import  javax.xml.parsers.DocumentBuilderFactory;

import  org.w3c.dom.Document;
import  org.w3c.dom.Element;
import  org.w3c.dom.Node;
import  org.w3c.dom.NodeList;

public   class  Read_XML_File  {
    
public static void main(String argv[]) {
        
try {
            File file 
= new File("test_files/test.xml");
            DocumentBuilderFactory dbf 
= DocumentBuilderFactory.newInstance();
            DocumentBuilder db 
= dbf.newDocumentBuilder();
            Document doc 
= db.parse(file);
            doc.getDocumentElement().normalize();
            System.out.println(
"Root element "
                    
+ doc.getDocumentElement().getNodeName());
            NodeList nodeLst 
= doc.getElementsByTagName("employee");
            System.out.println(
"Information of all employees");
            
            
for (int s = 0; s < nodeLst.getLength(); s++{

                Node fstNode 
= nodeLst.item(s);

                
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {

                    Element fstElmnt 
= (Element) fstNode;
                    NodeList fstNmElmntLst 
= fstElmnt
                            .getElementsByTagName(
"firstname");
                    Element fstNmElmnt 
= (Element) fstNmElmntLst.item(0);
                    NodeList fstNm 
= fstNmElmnt.getChildNodes();
                    System.out.println(
"First Name : "
                            
+ ((Node) fstNm.item(0)).getNodeValue());
                    NodeList lstNmElmntLst 
= fstElmnt
                            .getElementsByTagName(
"lastname");
                    Element lstNmElmnt 
= (Element) lstNmElmntLst.item(0);
                    NodeList lstNm 
= lstNmElmnt.getChildNodes();
                    System.out.println(
"Last Name : "
                            
+ ((Node) lstNm.item(0)).getNodeValue());
                }


            }

        }
 catch (Exception e) {
            e.printStackTrace();
        }

    }


}


2.2 read .properties file
copy from http://www.exampledepot.com/egs/java.util/Props.html

test.properties

# a comment
! a comment 
a = a string
b = a string with escape sequences /t /n /r // /" /' / (space) /u0123
c = a string with a continuation line /
        continuation line
d.e.f = another string

 

package  readfile;

import  java.io.FileInputStream;
import  java.io.IOException;
import  java.util.Properties;

public   class  Read_Properties_File  {
 
public static void main(String[] args) {
  
// Read properties file.
  Properties properties = new Properties();
  
try {
   properties.load(
new FileInputStream("test_files/test.properties"));
  }
 catch (IOException e) {
  }

  String string1 
= properties.getProperty("a");//get "a string"
  
  String string2 
= properties.getProperty("d.e.f");//get "another string"
  
  properties.setProperty(
"a.b""new value");
  
  String string3 
= properties.getProperty("a.b");//get "new value"
  
 }

}



 

你可能感兴趣的:(logging,import,properties,table,string,file)