📄 xmlstatement.java
字号:
throw new SQLException("Column '" + xxx[i] + "' not found in table "+parser.getTableName());
}
}
catch (Exception e)
{
throw new SQLException("Error reading data file. Message was: " + e);
}
XmlResultSet resultSet = new XmlResultSet(this, reader,
parser.getTableName(), parser.getColumnNames() , parser.getWhereColumnNames() , parser.getWhereColumnValues());
resultSet.select();
return resultSet;
} else {
throw new SQLException("Syntax error.Not supported sql statement.");
}
}
/**
* Insert data into XML database
*
* @param sql Description of Parameter
* @return Description of the Returned Value
* @exception SQLException Description of Exception
* @since
*/
public int executeUpdate(String sql) throws SQLException
{
DriverManager.println("XmlJdbc - XmlStatement:executeUpdate() - sql= " + sql);
XmlSqlParser parser = new XmlSqlParser();
try
{
parser.parse(sql);
}
catch (Exception e)
{
throw new SQLException("Syntax Error. " + e.getMessage());
}
if(parser.sqlType.equals(parser.SELECT))
throw new SQLException("Not supported SELECT statement - use executeQuery() method");
else if (parser.sqlType.equals(parser.CREATE_TABLE)) {
throw new SQLException("Not supported CREATE_TABLE statement - use execute() method");
}
else if (parser.sqlType.equals(parser.DROP_TABLE)) {
throw new SQLException("Not supported DROP_TABLE statement - use execute() method");
}
else if (parser.sqlType.equals(parser.INSERT)) {
String fileName = connection.getPath() + connection.getExtension();
XmlWriter writeXml;
try
{
if( this.connection.getAutoCommit() )
writeXml = new XmlWriter(fileName,true);
else
writeXml = new XmlWriter(fileName,false);
ArrayList properties = writeXml.getTableProperties( parser.tableName );
//check for existance of columns
String[] xxx = parser.getColumnNames();
String[] yyy = (String[])properties.get(0);
boolean isOK = true;
for(int i=0; i< xxx.length; i++) {
if(!xxx[i].endsWith("*")) {
out:
for(int j=0; j< yyy.length; j++) {
if(xxx[i].equalsIgnoreCase(yyy[j])) {
isOK=true;
break out;
}
else
isOK=false;
}
if(!isOK)
throw new SQLException("Column '" + xxx[i] + "' not found in table "+parser.getTableName());
}
}
//check if NOTNULL columns is set
if( !properties.get(1).toString().equalsIgnoreCase("NO CREATE TABLE") ) {
yyy = parser.getColumnNames();
xxx = (String[])writeXml.getTableProperties( parser.tableName ).get(2);
isOK = true;
for(int i=0; i< xxx.length; i++) {
out:
for(int j=0; j< yyy.length; j++) {
if(xxx[i].equalsIgnoreCase(yyy[j])) {
isOK=true;
break out;
}
else
isOK=false;
}
if(!isOK)
throw new SQLException("Column '" + xxx[i] + "' can not be NULL.");
}
}
writeXml.insert( parser.getTableName() , parser.getColumnNames() , parser.getColumnValues() );
}
catch (Exception e)
{
throw new SQLException("Error reading data file. Message was: " + e);
}
}
else if (parser.sqlType.equals(parser.UPDATE)) {
String fileName = connection.getPath() + connection.getExtension();
XmlWriter writeXml;
try
{
if( this.connection.getAutoCommit() )
writeXml = new XmlWriter(fileName,true);
else
writeXml = new XmlWriter(fileName,false);
String[] xxx = parser.getColumnNames();
String[] yyy = (String[])writeXml.getTableProperties( parser.tableName ).get(0);
boolean isOK = true;
for(int i=0; i< xxx.length; i++) {
if(!xxx[i].endsWith("*")) {
out:
for(int j=0; j< yyy.length; j++) {
if(xxx[i].equalsIgnoreCase(yyy[j])) {
isOK=true;
break out;
}
else
isOK=false;
}
if(!isOK)
throw new SQLException("Column '" + xxx[i] + "' not found in table "+parser.getTableName());
}
}
writeXml.update( parser.getTableName() , parser.getColumnNames() , parser.getColumnValues() , parser.getWhereColumnNames() , parser.getWhereColumnValues() );
}
catch (Exception e)
{
throw new SQLException("Error reading data file. Message was: " + e);
}
}
else if (parser.sqlType.equals(parser.DELETE)) {
String fileName = connection.getPath() + connection.getExtension();
XmlWriter writeXml;
try
{
if( this.connection.getAutoCommit() )
writeXml = new XmlWriter(fileName,true);
else
writeXml = new XmlWriter(fileName,false);
String[] xxx = parser.getWhereColumnNames();
String[] yyy = (String[])writeXml.getTableProperties( parser.tableName ).get(0);
boolean isOK = true;
for(int i=0; i< xxx.length; i++) {
if(!xxx[i].endsWith("*")) {
out:
for(int j=0; j< yyy.length; j++) {
if(xxx[i].equalsIgnoreCase(yyy[j])) {
isOK=true;
break out;
}
else
isOK=false;
}
if(!isOK)
throw new SQLException("Column '" + xxx[i] + "' not found in table "+parser.getTableName());
}
}
writeXml.delete( parser.getTableName() , parser.getWhereColumnNames() , parser.getWhereColumnValues() );
}
catch (Exception e)
{
throw new SQLException("Error reading data file. Message was: " + e);
}
}
else if (parser.sqlType.equals(parser.DROP_TABLE)) {
}
return 0;
}
/**
* Releases this <code>Statement</code> object's database
* and JDBC resources immediately instead of waiting for
* this to happen when it is automatically closed.
* It is generally good practice to release resources as soon as
* you are finished with them to avoid tying up database
* resources.
* <P>
* Calling the method <code>close</code> on a <code>Statement</code>
* object that is already closed has no effect.
* <P>
* <B>Note:</B> A <code>Statement</code> object is automatically closed
* when it is garbage collected. When a <code>Statement</code> object is
* closed, its current <code>ResultSet</code> object, if one exists, is
* also closed.
*
* @exception SQLException if a database access error occurs
*/
public void close() throws SQLException {
}
/**
*Description of the Method
*
* @exception SQLException Description of Exception
* @since
*/
public void cancel() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Description of the Method
*
* @exception SQLException Description of Exception
* @since
*/
public void clearWarnings() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Description of the Method
*
* @param sql Description of Parameter
* @return Description of the Returned Value
* @exception SQLException Description of Exception
* @since
*/
public boolean execute(String sql) throws SQLException
{
XmlWriter writeXml;
if( this.connection.getAutoCommit() )
writeXml = new XmlWriter(fileName,true);
else
writeXml = new XmlWriter(fileName,false);
XmlSqlParser parser = new XmlSqlParser( this.fileName, this.connection.getAutoCommit() );
try
{
parser.parse(sql);
}
catch (Exception e)
{
throw new SQLException("Syntax Error. " + e.getMessage());
}
if(parser.sqlType.equals(parser.SELECT))
throw new SQLException("Use executeQuery() for SELECT statement");
else if (parser.sqlType.equals(parser.UPDATE))
executeUpdate(sql);
else if (parser.sqlType.equals(parser.INSERT))
executeUpdate(sql);
else if (parser.sqlType.equals(parser.DELETE))
executeUpdate(sql);
else if (parser.sqlType.equals(parser.CREATE_TABLE)) {
String fileName = connection.getPath() + connection.getExtension();
try
{
writeXml.createTable( parser.getSqlStatement() , parser.getTableName() );
}
catch (Exception e)
{
throw new SQLException("Error reading data file. Message was: " + e);
}
} else if (parser.sqlType.equals(parser.DROP_TABLE)) {
String fileName = connection.getPath() + connection.getExtension();
try
{
writeXml.dropTable( parser.getTableName() );
}
catch (Exception e)
{
throw new SQLException("Error reading data file. Message was: " + e);
}
}
return true;
}
/**
*Adds a feature to the Batch attribute of the XmlStatement object
*
* @param p0 The feature to be added to the Batch attribute
* @exception SQLException Description of Exception
* @since
*/
public void addBatch(String p0) throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Description of the Method
*
* @exception SQLException Description of Exception
* @since
*/
public void clearBatch() throws SQLException
{
throw new SQLException("Not Supported !");
}
/**
*Description of the Method
*
* @return Description of the Returned Value
* @exception SQLException Description of Exception
* @since
*/
public int[] executeBatch() throws SQLException
{
throw new SQLException("Not Supported !");
}
//---------------------------------------------------------------------
// JDBC 3.0
//---------------------------------------------------------------------
public boolean getMoreResults(int current) throws SQLException {
throw new UnsupportedOperationException("Statement.getMoreResults(int) unsupported");
}
public ResultSet getGeneratedKeys() throws SQLException {
throw new UnsupportedOperationException("Statement.getGeneratedKeys() unsupported");
}
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
throw new UnsupportedOperationException("Statement.executeUpdate(String,int) unsupported");
}
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
throw new UnsupportedOperationException("Statement.executeUpdate(String,int[]) unsupported");
}
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
throw new UnsupportedOperationException("Statement.executeUpdate(String,String[]) unsupported");
}
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
throw new UnsupportedOperationException("Statement.execute(String,int) unsupported");
}
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
throw new UnsupportedOperationException("Statement.execute(String,int[]) unsupported");
}
public boolean execute(String sql, String[] columnNames) throws SQLException {
throw new UnsupportedOperationException("Statement.execute(String,String[]) unsupported");
}
public int getResultSetHoldability() throws SQLException {
throw new UnsupportedOperationException("Statement.getResultSetHoldability() unsupported");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -