java createStatement()方法如何返回语句的对象?
根据javadoc,createStatement()
方法创建一个Statement
实例,用于向数据库发送SQL语句
现在Statement
是java.sql
包下的interface
,我的理解是,不可能在Java中创建接口的实例
那它是怎么工作的? 我从源头上找到了这个,只是我不明白
/**
* Creates a <code>Statement</code> object for sending
* SQL statements to the database.
* SQL statements without parameters are normally
* executed using <code>Statement</code> objects. If the same SQL statement
* is executed many times, it may be more efficient to use a
* <code>PreparedStatement</code> object.
* <P>
* Result sets created using the returned <code>Statement</code>
* object will by default be type <code>TYPE_FORWARD_ONLY</code>
* and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @return a new default <code>Statement</code> object
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
*/
Statement createStatement() throws SQLException;
# 1 楼答案
下面是一些示例代码:
胡闹。getStatement()返回对实现IBlammy接口的对象的引用
# 2 楼答案
您正在查看
Connection
的接口的源代码,而不是类。接口不包含任何类型的实现——它们只是定义了一个契约,实现该接口的类必须实现该接口上的所有内容http://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html