.NET程序员学Java笔记[5]-连接MySQL并读取Metadata及Log4j应用

/**
 * 说明:
 * 需要引用log4j-1.2.15.jar与mysql-connector-java-5.1.7-bin.jar
 * log4j.properties配置如下:
  log4j.rootLogger=debug, stdout, R
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

  # Pattern to output the caller's file name and line number.
  log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

  log4j.appender.R=org.apache.log4j.RollingFileAppender
  log4j.appender.R.File=example.log
  log4j.appender.R.MaxFileSize= 100KB

  # Keep one backup file
  log4j.appender.R.MaxBackupIndex=1

  log4j.appender.R.layout=org.apache.log4j.PatternLayout
  log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n        
 */

package net.io99;

import java.sql.*;
import org.apache.log4j.*;


public class TestMetaData {

	static Logger logger = Logger.getLogger(TestMetaData.class);
	
	/**
	 * @param args
	 * @throws ClassNotFoundException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
		String url = "jdbc:mysql://localhost:3306/test?characterEncoding=utf-8";
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		try {
			Connection conn = DriverManager.getConnection(url,"root","");
			DatabaseMetaData meta = conn.getMetaData();
			System.out.println(meta.getURL());
		} catch (SQLException e) {
			logger.error(e);
		}
		

	}

}
 

你可能感兴趣的:(java,apache,log4j,.net,mysql)