Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there any generic based alternatives for setting parameters in PrepareStatement
    primarykey
    data
    text
    <p>I am developing a database application. Currently I am using java.sql combined with H2 embedded database. I would like to develop the <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself" rel="nofollow">Don't Repeat Yourself</a> way.<br> So I set up a reuseable Database Row class and Database Property class as follows: public class DatabaseProperty { private String PropertyName; private T Value; private boolean Identifier;</p> <pre><code>public DatabaseProperty(String PropertyName, T Value, boolean identifier) { this.PropertyName = PropertyName; this.Value = Value; this.Identifier = identifier; } public String getPropertyName() { return PropertyName; } public T getValue() { return Value; } public void setValue(T Value) { this.Value = Value; } public boolean isIdentifier() { return Identifier; } } </code></pre> <p>And... public class DatabaseRow { protected Connection DBConnection; protected String TableName; protected HashSet = new HashSet&lt;>();</p> <pre><code> public DatabaseRow() //With all the above variables. Apologies for being lazy to type ;) //Here's the problem part //I'm trying to automatically generate an SQL Statement //to check that the row specified by primary unique keys (ex:- Username and Password Combination for Log In) public boolean existsInTable(){ try { String SQL = "SELECT * FROM "+TableName+" WHERE "; boolean addAND = false; for(DatabaseProperty d:Columns) { if(d.isIdentifier()) { SQL+=(addAND?"AND ":"")+d.getPropertyName()+" = ? "; addAND = true; } } PreparedStatement ps = getDBConnection().prepareStatement(SQL); </code></pre> <p>And the code goes on...<br> The problem is that I do not have Generic based methods for setting parameters in PeparedStatement class. Instead there is setString(int index,String s), etc.. Please help me to overcome this.. Is there any object oriented wrappers available, like <a href="http://www.notorm.com" rel="nofollow">NotORM</a> for PHP? Is there any trade off between performance and coding ease with such options?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload