package com.chenyang.nse.bussiness.test;

import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Mysqltest {
   public static void main(String[] args) throws ClassNotFoundException, SQLException, UnsupportedEncodingException {
      String url = "jdbc:mysql://192.168.2.202:3306/testcon?zeroDateTimeBehavior=convertToNull";
      String driver = "com.mysql.jdbc.Driver";
      String passwd = "root";
      String user = "root";
      Class.forName(driver);
      Connection conn = DriverManager.getConnection(url, passwd, user);
      String sql = "select   name1 from test3 a";
      PreparedStatement ps = conn.prepareStatement(sql);
      ResultSet rs = ps.executeQuery();
      DatabaseMetaData metaData = conn.getMetaData();
      ResultSet tableTypes = metaData.getTableTypes();

      while(rs.next()) {
         String name = rs.getString("name1");
         String columnValue = new String(name.getBytes("ISO8859_1"), "utf-8");
         System.out.println(columnValue);
      }

      ps.close();
      conn.close();
   }
}
