这是我正在测试以处理错误的原始代码的片段。
第一种方法是调用fatalErrorHandler(),但第二种方法不是调用fatalErrorHandler(). 可能是什么原因?
第一的
<?php
//error_reporting(0);
function fatalErrorHandler() {
echo 'YAY IT WORKED';
}
# Registering shutdown function
register_shutdown_function('fatalErrorHandler');
// let force a Fatal error -- function does not exist
functiontest();
echo "hello";
?>
Run Code Online (Sandbox Code Playgroud)
输出:
致命错误:在第 12 行的 ...test2.php 中调用未定义的函数 functiontest() YAY IT WORKED
第二
<?php
//error_reporting(0);
function fatalErrorHandler() {
echo 'YAY IT WORKED';
}
# Registering shutdown function
register_shutdown_function('fatalErrorHandler');
// let force a Fatal error -- function does not exist
functiontest();
function foo () { …Run Code Online (Sandbox Code Playgroud) 我按照以下教程从存储过程中检索XMLType数据
http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb11jav.htm#g1039140 示例13-4 XMLType Java:返回XMLType数据
当我运行代码时,我收到此错误,
Exception in thread "main" java.lang.NoClassDefFoundError: oracle/xml/parser/v2/XMLParseException
at oracle.xdb.XMLTypeFactory.create(XMLTypeFactory.java:67)
at oracle.sql.OPAQUE.toClass(OPAQUE.java:328)
at oracle.sql.OPAQUE.toJdbc(OPAQUE.java:278)
at oracle.sql.OPAQUE.toJdbc(OPAQUE.java:259)
at oracle.jdbc.driver.NamedTypeAccessor.getObject(NamedTypeAccessor.java:190)
at oracle.jdbc.driver.NamedTypeAccessor.getObject(NamedTypeAccessor.java:117)
at oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:1579)
at oracle.jdbc.driver.OracleCallableStatementWrapper.getObject(OracleCallableStatementWrapper.java:815)
at com.example.TestXMLDAO.main(TestXMLDAO.java:48)
Caused by: java.lang.ClassNotFoundException: oracle.xml.parser.v2.XMLParseException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 9 more
Run Code Online (Sandbox Code Playgroud)
Java代码片段:
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import oracle.jdbc.OracleTypes;
import oracle.xdb.XMLType;
Run Code Online (Sandbox Code Playgroud)
.............
// Prepare to call the stored procedure …Run Code Online (Sandbox Code Playgroud) 对于条件检查我们要么去<xsl:choose>或<xsl:if>
<xsl:choose>
<xsl:when test="expression">
... some output ...
</xsl:when>
<xsl:otherwise>
... some output ....
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$admin=$value1">
<control>true</control>
</xsl:if>
<xsl:if test="not($admin=$value1)">
<control>false</control>
</xsl:if>
Run Code Online (Sandbox Code Playgroud)
为什么没有<xsl:else>定义标签?
当我使用时<xsl:if>,如果有<xsl:else>,我不需要重复这个test="not($admin=$value1)条件.
<xsl:choose>当你有多个案件要检查时,这是好事.当然上面会模拟一个典型的' if-else ',但为什么这么多代码行来模拟if-else条件
我想知道为什么没有<xsl:else>为XSL定义标签?有什么想法吗?
以下是如何正确的?我希望编译器告诉我使用throws Exception或throws RuntimeException
public void method1() throws NullPointerException {
throw new RuntimeException();
}
Run Code Online (Sandbox Code Playgroud)
为什么我认为它不正确 - > Bcoz NPE是RTE,但RTE不是NPE
这怎么回事?我希望编译器告诉我使用throws Exception或throws RuntimeException或throws NumberFormatException
public void method2() throws NullPointerException {
throw new NumberFormatException();
}
public void method3() throws Exception { // this is fine, as expected
throw new RuntimeException();
}
public void method4() throws RuntimeException { // this is fine, as expected
throw new NullPointerException();
}
public void method5() throws Exception { // this …Run Code Online (Sandbox Code Playgroud) 我最近观察到一个奇怪的事情,比较两个Java Date对象与equals().请注意,this.getDate()和other.getDate()都将在我的应用程序中返回Java Date对象.
码:
logger.debug("Date 1: " + this.getDate().toString());
logger.debug("Date 1: " + this.getDate().getTime());
logger.debug("Date 2: " + other.getDate().toString());
logger.debug("Date 2: " + other.getDate().getTime());
logger.debug("Dates are equal: " + this.getDate().equals(other.getDate()));
logger.debug("Dates match in comparison: " + (this.getDate().compareTo(other.getDate()) == 0));
Run Code Online (Sandbox Code Playgroud)
输出:(添加空行以提高可读性)
Date 1: 2014-07-28 00:00:00.0
Date 1: 1406498400000
Date 2: Mon Jul 28 00:00:00 CEST 2014
Date 2: 1406498400000
Dates are equal: false
Dates match in comparison: true
Run Code Online (Sandbox Code Playgroud)
我有两件事没有得到:
我检查了Date.equals()的文档,其中说:
比较两个相等的日期.当且仅当参数不为null并且是一个Date对象时,结果才为真,该对象表示与此对象相同的时间点,以毫秒为单位.
因此,当且仅当getTime方法为两者返回相同的long值时,两个Date对象才相等.
我还看了一下Date.equals()的实现:
public boolean …Run Code Online (Sandbox Code Playgroud) 下面的代码利用bootstrap data-toggle="collapse"来点击已配置的元素来执行折叠/展开功能,在这种情况下,单击parent1和parent2
问题:点击parent元素后,崩溃就可以通过我的电脑使用Chrome和Firefox浏览器进行,但是我的iPad无法使用safari浏览器.
<div id="parent1" type="button" class="parentclass" data-toggle="collapse" data-target="#childof1">
<strong>Technologies </strong>
</div>
<div id="childof1" class="collapse">
<!-- elements of child1 -->
</div
<div id="parent2" type="button" class="parentclass" data-toggle="collapse" data-target="#childof2">
<strong>Vertical </strong>
</div>
<div id="childof2" class="collapse">
<!-- elements of child2 -->
</div
Run Code Online (Sandbox Code Playgroud)
参考文献:http://www.w3schools.com/bootstrap/bootstrap_ref_js_collapse.asp
我在尝试连接到oracle数据库时收到以下错误,当我在网上搜索时,建议是在类路径上添加所需的jar,我已经这样做了.我甚至尝试创建一个运行配置,在类路径上添加jar,仍然得到相同的错误.
请帮忙,
错误:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no ocijdbc9 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1738)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at oracle.jdbc.oci8.OCIDBAccess.logon(OCIDBAccess.java:262)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:346)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.example.DAO1.main(DAO1.java:13)
Run Code Online (Sandbox Code Playgroud)
码:
package com.example;
import java.sql.*;
import java.io.*;
class DAO1 {
public static void main(String args[]) throws SQLException, IOException {
// Load the driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn = …Run Code Online (Sandbox Code Playgroud) SqlOutParameter out = new SqlOutParameter("out_refcursor",OracleTypes.CURSOR,new StudentRowMapper());
Run Code Online (Sandbox Code Playgroud)
//一些代码..
MapSqlParameterSource parameters = createMapSqlParameterSource();
parameters.addValue("in_studentid","101");
Map<String, Object> result = simpleJdbcCall.execute(parameters);
List<Student> students = (List<Student>) result.get("out_refcursor"); // here I get a warning
Run Code Online (Sandbox Code Playgroud)
execute()方法的定义:
Map<String, Object> org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SqlParameterSource parameterSource)
Run Code Online (Sandbox Code Playgroud)
"执行存储过程并返回输出参数的映射,按参数声明中的名称键入.."
以上警告: List<Student> students = (List<Student>) result.get("out_refcursor");
是"类型安全:未选中从对象转换为列表"
我知道这只是一个编译时警告,而且我可以做一个@SuppressWarnings("unchecked")来压制它.
问题:但我该如何正确施展呢?
我试过的一种方法是
List<Student> students = castObject( result.get("out_refcursor"));
@SuppressWarnings("unchecked")
private static <T extends List<?>> T castObject(Object obj){
return (T)obj;
}
Run Code Online (Sandbox Code Playgroud)我仍然需要放入@SuppressWarnings("unchecked")castObject()方法.我不知道这是否是正确的做法.
我尝试的第二种方式是,
List<?> students = castObject( result.get("out_refcursor"));
Student student = (Student)students.get(0);
private static …Run Code Online (Sandbox Code Playgroud)