If you think the Android project jepldroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package jepl.impl.nonjta.android;
//fromwww.java2s.comimport java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import jepl.JEPLException;
import jepl.impl.JEPLDALImpl;
import jepl.impl.JEPLPreparedStatementImpl;
import jepl.impl.nonjta.JEPLNonJTAConnectionImpl;
publicclass JEPLNonJTAConnectionSQLDroidImpl extends JEPLNonJTAConnectionImpl
{
protected Field androidCursorField;
protected Method androidMoveToPositionMethod;
public JEPLNonJTAConnectionSQLDroidImpl(JEPLNonJTADataSourceAndroidImpl ds,Connection con) throws SQLException
{
super(ds,con);
}
protected JEPLPreparedStatementImpl createJEPLPreparedStatement(JEPLDALImpl dal,PreparedStatement stmt,String key) throws SQLException
{
returnnew JEPLPreparedStatementSQLDroidImpl(this,dal,stmt,key);
}
@Override
protected PreparedStatement prepareStatement(String sql,int autoGeneratedKeys) throws SQLException
{
// No est soportado prepareStatement(sql, autoGeneratedKeys)
return con.prepareStatement(sql);
}
publicvoid moveResultSetAbsolutePosition(ResultSet result, int position)
{
try
{
if (androidCursorField == null)
{
this.androidCursorField = result.getClass().getDeclaredField("c"); // Es un atributo privado de SqldroidResultSet (no usar getField que requiere que sea pblico)
androidCursorField.setAccessible(true); // Es privado el atributo
}
Object cursor = androidCursorField.get(result); //android.database.Cursor
if (androidMoveToPositionMethod == null)
{
// moveToPosition(int position)
this.androidMoveToPositionMethod = cursor.getClass().getMethod("moveToPosition", new Class[]{int.class}); // Usamos getMethod porque es un mtodo pblico de Android y no getDeclaredMethod no sea que no est en esa clase exactamente
}
androidMoveToPositionMethod.invoke(cursor, position - 1);
}
catch (InvocationTargetException ex)
{
thrownew JEPLException(ex);
}
catch (NoSuchMethodException ex)
{
thrownew JEPLException(ex);
}
catch (IllegalAccessException ex)
{
thrownew JEPLException(ex);
}
catch (NoSuchFieldException ex)
{
thrownew JEPLException(ex);
}
}
}