当前位置: 首页>>代码示例>>Java>>正文


Java DriverManager.println方法代码示例

本文整理汇总了Java中java.sql.DriverManager.println方法的典型用法代码示例。如果您正苦于以下问题:Java DriverManager.println方法的具体用法?Java DriverManager.println怎么用?Java DriverManager.println使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.DriverManager的用法示例。


在下文中一共展示了DriverManager.println方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tests17

import java.sql.DriverManager; //导入方法依赖的package包/类
/**
 * Create a PrintStream and use to send output via DriverManager.println
 * Validate that if you disable the stream, the output sent is not present
 */
@Test
public void tests17() throws Exception {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    DriverManager.setLogStream(ps);
    assertTrue(DriverManager.getLogStream() == ps);

    DriverManager.println(results[0]);
    DriverManager.setLogStream((PrintStream) null);
    assertTrue(DriverManager.getLogStream() == null);
    DriverManager.println(noOutput);
    DriverManager.setLogStream(ps);
    DriverManager.println(results[1]);
    DriverManager.println(results[2]);
    DriverManager.println(results[3]);
    DriverManager.setLogStream((PrintStream) null);
    DriverManager.println(noOutput);

    /*
     * Check we do not get the output when the stream is disabled
     */
    InputStreamReader is
            = new InputStreamReader(new ByteArrayInputStream(os.toByteArray()));
    BufferedReader reader = new BufferedReader(is);
    for (String result : results) {
        assertTrue(result.equals(reader.readLine()));
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:DriverManagerTests.java

示例2: tests18

import java.sql.DriverManager; //导入方法依赖的package包/类
/**
 * Create a PrintWriter and use to to send output via DriverManager.println
 * Validate that if you disable the writer, the output sent is not present
 */
@Test
public void tests18() throws Exception {
    CharArrayWriter cw = new CharArrayWriter();
    PrintWriter pw = new PrintWriter(cw);
    DriverManager.setLogWriter(pw);
    assertTrue(DriverManager.getLogWriter() == pw);

    DriverManager.println(results[0]);
    DriverManager.setLogWriter(null);
    assertTrue(DriverManager.getLogWriter() == null);
    DriverManager.println(noOutput);
    DriverManager.setLogWriter(pw);
    DriverManager.println(results[1]);
    DriverManager.println(results[2]);
    DriverManager.println(results[3]);
    DriverManager.setLogWriter(null);
    DriverManager.println(noOutput);

    /*
     * Check we do not get the output when the stream is disabled
     */
    BufferedReader reader
            = new BufferedReader(new CharArrayReader(cw.toCharArray()));
    for (String result : results) {
        assertTrue(result.equals(reader.readLine()));
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:32,代码来源:DriverManagerTests.java


注:本文中的java.sql.DriverManager.println方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。