0

我在 cloudera 集群上安装了 Apache Phoenix。我正在尝试连接到数据库并运行一些简单的 SQL 命令。我的代码如下。我在本地创建一个可执行的 jar 文件并在集群上运行它。

我收到以下警告。有谁知道它们是什么。

log4j:WARN No appenders could be found for logger (org.apache.hadoop.conf.Configuration.deprecation).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.


package mysqljbdctest;
import java.sql.*
public class PhoenixJDBC {

public static void main(String args[]) {

String connectionURL = "jdbc:phoenix:52.153.31.118:2181,52.153.111.8:2181,52.134.169.130:2181";

try {
    //Register JDBC Driver
    Class.forName("org.apache.phoenix.jdbc.PhoenixDriver").newInstance();

    Connection conn = DriverManager.getConnection("jdbc:phoenix:54.154.34.128","","");

    //Create a Statement class to execute the SQL statement
    Statement stmt = conn.createStatement();

    //Execute the SQL statement and get the results in a Resultset
    ResultSet rs = stmt.executeQuery("select * from STOCK_SYMBOL");

    // Iterate through the ResultSet, displaying two values
    // for each row using the getString method

    while (rs.next())
        System.out.println("Name= " + rs.getString("host"));
}
catch (SQLException e) {
    e.printStackTrace();
}
catch (Exception e) {
    e.printStackTrace();
}
}
}
4

1 回答 1

0

在类路径中添加 log4j.xml 或 log4j.properties 并重试,对于独立的 Java 应用程序,确保 log4j.properties 文件位于 project/classes 目录下 对于 Java Web 应用程序,确保 log4j.properties 文件位于 WEB-下面的 INF/classes 目录是一个示例

# Root logger option
log4j.rootLogger=DEBUG, stdout, file 
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}   %-5p %c{1}:%L - %m%n 
于 2015-02-17T16:52:35.387 回答