SQLibrary icon indicating copy to clipboard operation
SQLibrary copied to clipboard

sql.setString not recognized

Open micheldewit opened this issue 8 years ago • 1 comments

Good afternoon:

We are busy building a plugin, and not to reinvent the SQLWheel we are using SQLibrary, and we are wondering how to achieve the following:

For security purposes we want to use Prepare statements (sql.prepare("Insert into ? value(?,?) for example). However, when using the follow up statements sql.setString, sql.setDouble and sql.setInt etc we are getting The method setString(int, String) is undefined for the type Database.

How do we achieve the setString etc without having to recode the whole SQLibrary ourselfs, to add support to do this?

micheldewit avatar Dec 21 '16 03:12 micheldewit

Thanks for the issue Michel! Since you don't want to reinvent the SQL libraries out there, have you tried the Bukkit API ORM? SQLibrary has essentially been deprecated in favor of it.

  1. Start by reverse engineering your tables into JavaX Persistence entities:

https://www.eclipse.org/webtools/dali/docs/3.2/user_guide/tasks006.htm

  1. Define an override method in your central plugin class with all of your JavaX Persistence classes:
    @Override
    public List<Class<?>> getDatabaseClasses() {
            List<Class<?>> list = new ArrayList<Class<?>>();
            list.add(Clazz.class);
            return list;
    }
  1. To create queries, run:

MyPlugin.getInstance().getDatabase().find(Clazz.class).where()...

http://ebean-orm.github.io/apidocs/com/avaje/ebean/Query.html

And that should be it! It's very, very easy to use once you get the classes generated and exactly what I originally wanted SQLibrary to become.

http://wiki.bukkit.org/Plugin_Databases

PatPeter avatar Dec 22 '16 00:12 PatPeter