SQLite error

Discussion in 'Plugin Development' started by TechGuard, Jul 16, 2011.

Thread Status:
Not open for further replies.
  1. Code:
    14:14:54 [INFO] [iZone : 6.6] Error at SQL INSERT Query: java.sql.SQLExce
    [SQLITE_ERROR] SQL error or missing database (near "flag": syntax error)
    What does that error mean?
    Sorry, i'm new to SQL stuff.
     
  2. Offline

    Hretsam

    Did you connect to a database, or is there an database in your sql statement?
     
  3. Code:
    public iZone plugin;
        public String dbLocation;
        public String dbName;
        private DatabaseHandler manageDB;
    
        public sqlCore(iZone instance, String dbName, String dbLocation) {
            this.plugin = instance;
            this.dbName = dbName;
            this.dbLocation = dbLocation;
    
        }
    
        public Boolean initialize() {
            File dbFolder = new File(dbLocation);
            if (dbName.contains("/") || dbName.contains("\\") || dbName.endsWith(".db")) { this.writeError("The database name can not contain: /, \\, or .db", true); return false; }
            if (!dbFolder.exists()) {
                dbFolder.mkdir();
            }
    
            File SQLFile = new File(dbFolder.getAbsolutePath() + "/" + dbName);
    
            this.manageDB = new DatabaseHandler(this, SQLFile);
    
            return this.manageDB.initialize();
        }
    This is the this.manageDB.initialize(); method:
    Code:
    public Boolean initialize() {
            try {
              Class.forName("org.sqlite.JDBC");
              connection = DriverManager.getConnection("jdbc:sqlite:" + SQLFile.getAbsolutePath());
              return true;
            } catch (SQLException ex) {
              core.writeError("SQLite exception on initialize " + ex, true);
            } catch (ClassNotFoundException ex) {
              core.writeError("You need the SQLite library " + ex, true);
            }
            return false;
        }
     
  4. Your error means that the database you're trying to access does not exist or there is an error with your statement.

    Post your query and I'll check it :D
     
  5. Offline

    Hretsam

  6. Code:
    
    String flags = "protection BOOL,pvp BOOL,monsters BOOL,animal BOOL,";
    		String query = "CREATE TABLE "+DB_Table+" (" +
    			"name VARCHAR(32)," +
    			"world VARCHAR(32)," +
    			"welcome VARCHAR(50)," +
    			"farewell VARCHAR(50)," +
    			"mix INT, miy INT, miz INT," +
    			"max INT, may INT, maz INT," +
    			flags+"" +
    			"allowed TEXT" +
    		");";
    manageSQLite = new sqlCore(plug, DB_Name, dataFolder);
                manageSQLite.initialize();
    
                try{
                    if(!manageSQLite.checkTable(DB_Table)){
                        manageSQLite.createTable(query);
                    }
                }catch(Exception e){
                    e.printStackTrace();
                }
     
Thread Status:
Not open for further replies.

Share This Page