📄 xmlpreparedstatement.java
字号:
package org.webdocwf.util.xml;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.io.InputStream;
import java.io.Reader;
import java.sql.Ref;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Array;
import java.sql.ResultSetMetaData;
import java.util.Calendar;
import java.net.URL;
import java.sql.ParameterMetaData;
import java.sql.SQLWarning;
import java.sql.Connection;
import java.sql.DriverManager;
import java.io.File;
import java.util.*;
/**
* Class implements the JDBC PreparedStatement interface for the XmlJdbc driver.
*
* @author Zoran Milakovic
*/
public class XmlPreparedStatement implements PreparedStatement {
private XmlConnection connection;
private Vector resultSets = new Vector();
private String sqlForPrepare = "";
private String sqlPrepared = "";
private int paramCount = 0;
private ArrayList parameters = new ArrayList();
private ArrayList binaryStreamParameters = new ArrayList();
private String fileName;
public static String PREPARE_SEPARATOR = "~@#NEXTPARAMETER#@~";
public XmlPreparedStatement(XmlConnection connection, String preparedSql) {
DriverManager.println("XmlJdbc - XmlStatement() - connection=" + connection);
this.sqlForPrepare = preparedSql;
this.sqlPrepared = preparedSql;
this.paramCount = countParameters(preparedSql);
for(int i = 0; i < paramCount; i++)
parameters.add("null");
this.connection = connection;
this.fileName = connection.getPath() + connection.getExtension();
}
private int countParameters(String sql) {
int count = 0;
int index = sql.indexOf(PREPARE_SEPARATOR);
while(index != -1) {
count++;
sql = sql.substring(index + 1);
index = sql.indexOf(PREPARE_SEPARATOR);
}
return count;
}
private boolean prepareSql() throws SQLException {
boolean retVal = true;
for(int i = 0; i < parameters.size(); i++) {
int index = sqlPrepared.indexOf(PREPARE_SEPARATOR);
if(index != -1) {
sqlPrepared = sqlPrepared.substring(0, index) +
parameters.get(i) +
sqlPrepared.substring(index + PREPARE_SEPARATOR.length());
}
}
if(sqlPrepared.indexOf(PREPARE_SEPARATOR) != -1)
throw new SQLException("All ? in prepared query has to be replaced with values.");
else if(parameters.size() < this.paramCount)
throw new SQLException(
"Number of setted parameters is less than number of parameters in statement.");
else if(parameters.size() > this.paramCount)
throw new SQLException(
"Number of setted parameters is greater than number of parameters in statement.");
return retVal;
}
/**
* Sets the maxFieldSize attribute of the XmlStatement object
*
* @param p0 The new maxFieldSize value
* @exception SQLException Description of Exception
* @since
*/
public void setMaxFieldSize(int p0) throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Sets the maxRows attribute of the XmlStatement object
*
* @param p0 The new maxRows value
* @exception SQLException Description of Exception
* @since
*/
public void setMaxRows(int p0) throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Sets the escapeProcessing attribute of the XmlStatement object
*
* @param p0 The new escapeProcessing value
* @exception SQLException Description of Exception
* @since
*/
public void setEscapeProcessing(boolean p0) throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Sets the queryTimeout attribute of the XmlStatement object
*
* @param p0 The new queryTimeout value
* @exception SQLException Description of Exception
* @since
*/
public void setQueryTimeout(int p0) throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Sets the cursorName attribute of the XmlStatement object
*
* @param p0 The new cursorName value
* @exception SQLException Description of Exception
* @since
*/
public void setCursorName(String p0) throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Sets the fetchDirection attribute of the XmlStatement object
*
* @param p0 The new fetchDirection value
* @exception SQLException Description of Exception
* @since
*/
public void setFetchDirection(int p0) throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Sets the fetchSize attribute of the XmlStatement object
*
* @param p0 The new fetchSize value
* @exception SQLException Description of Exception
* @since
*/
public void setFetchSize(int p0) throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Gets the maxFieldSize attribute of the XmlStatement object
*
* @return The maxFieldSize value
* @exception SQLException Description of Exception
* @since
*/
public int getMaxFieldSize() throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Gets the maxRows attribute of the XmlStatement object
*
* @return The maxRows value
* @exception SQLException Description of Exception
* @since
*/
public int getMaxRows() throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Gets the queryTimeout attribute of the XmlStatement object
*
* @return The queryTimeout value
* @exception SQLException Description of Exception
* @since
*/
public int getQueryTimeout() throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Gets the warnings attribute of the XmlStatement object
*
* @return The warnings value
* @exception SQLException Description of Exception
* @since
*/
public SQLWarning getWarnings() throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Gets the resultSet attribute of the XmlStatement object
*
* @return The resultSet value
* @exception SQLException Description of Exception
* @since
*/
public ResultSet getResultSet() throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Gets the updateCount attribute of the XmlStatement object
*
* @return The updateCount value
* @exception SQLException Description of Exception
* @since
*/
public int getUpdateCount() throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Gets the moreResults attribute of the XmlStatement object
*
* @return The moreResults value
* @exception SQLException Description of Exception
* @since
*/
public boolean getMoreResults() throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Gets the fetchDirection attribute of the XmlStatement object
*
* @return The fetchDirection value
* @exception SQLException Description of Exception
* @since
*/
public int getFetchDirection() throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Gets the fetchSize attribute of the XmlStatement object
*
* @return The fetchSize value
* @exception SQLException Description of Exception
* @since
*/
public int getFetchSize() throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Gets the resultSetConcurrency attribute of the XmlStatement object
*
* @return The resultSetConcurrency value
* @exception SQLException Description of Exception
* @since
*/
public int getResultSetConcurrency() throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Gets the resultSetType attribute of the XmlStatement object
*
* @return The resultSetType value
* @exception SQLException Description of Exception
* @since
*/
public int getResultSetType() throws SQLException {
throw new SQLException("Not Supported !");
}
/**
*Gets the connection attribute of the XmlStatement object
*
* @return The connection value
* @exception SQLException Description of Exception
* @since
*/
public Connection getConnection() throws SQLException {
return connection;
}
public ResultSet executeQuery(String sql) throws SQLException {
DriverManager.println("XmlJdbc - XmlStatement:executeQuery() - sql= " + sql);
XmlWriter writer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -