0 Replies - 344 Views - Last Post: 01 April 2012 - 06:33 AM Rate Topic: -----

#1 cornetto456  Icon User is offline

  • D.I.C Regular

Reputation: 21
  • View blog
  • Posts: 438
  • Joined: 03-January 11

Sqlite error when getting records out of the database

Posted 01 April 2012 - 06:33 AM

Hello, i'm developing a application where you can insert new records.
But how many records there already in is unkown so I used SELECT COUNT() now my problem is when I only have one record it print's it out but when I have multiple records I get this error:

2012-04-01 15:26:46 [SEVERE] java.sql.SQLException: [SQLITE_MISUSE]  Library used incorrectly (out of memory)
2012-04-01 15:26:46 [SEVERE] 	at org.sqlite.DB.newSQLException(DB.java:383)
2012-04-01 15:26:46 [SEVERE] 	at org.sqlite.DB.newSQLException(DB.java:387)
2012-04-01 15:26:46 [SEVERE] 	at org.sqlite.DB.throwex(DB.java:374)
2012-04-01 15:26:46 [SEVERE] 	at org.sqlite.NativeDB.prepare(Native Method)
2012-04-01 15:26:46 [SEVERE] 	at org.sqlite.DB.prepare(DB.java:123)
2012-04-01 15:26:46 [SEVERE] 	at org.sqlite.Stmt.executeQuery(Stmt.java:121)
2012-04-01 15:26:46 [SEVERE] 	at com.cj4.mbroker.MBroker$1.run(MBroker.java:63)
2012-04-01 15:26:46 [SEVERE] 	at org.bukkit.craftbukkit.scheduler.CraftWorker.run(CraftWorker.java:34)
2012-04-01 15:26:46 [SEVERE] 	at java.lang.Thread.run(Unknown Source)


This is my code:
package com.cj4.mbroker;

import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Logger;

import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

/**
 * Created by IntelliJ IDEA.
 * User: pb
 * Date: 1/04/12
 * Time: 12:28
 * To change this template use File | Settings | File Templates.
 */
public class MBroker extends JavaPlugin {
        private Logger log;
        private boolean broking = true;
        private Connection con;
        private ResultSet set;
        private Statement stmt;
        private int iCount;
    public void onEnable(){
    log = this.getLogger();
    log.info("|| MBroker enabled ||");
        try {
            connectDB();
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
        }
        if(broking){
        log.info("Were live!");
       
        this.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {

            public void run() {
            	try {
            		
        	       Class.forName("org.sqlite.JDBC");
        	      con = DriverManager.getConnection("jdbc:sqlite:msg.db3"); 
        	      stmt = con.createStatement();
        	      ResultSet counts = stmt.executeQuery("SELECT COUNT(id) as rowCount FROM msg");
        	      counts.next();
        	      iCount = counts.getInt("rowCount");
        	      log.info("Row count:" + iCount);
        	      
        	      counts.close();
        	      int moment = 0;
        	      while(moment != iCount){
        	    	  moment++;
	              set =  stmt.executeQuery("SELECT * FROM msg WHERE id='" + moment +"'");
	               while(set.next()){
	            	   getServer().broadcastMessage(set.getString("msg"));
	            	   
	               }
	               set.close();
	               stmt.close();
	               con.close();
	              
        	      }
        	    	  moment = 0;
        	      
                } catch (SQLException e) {
	                // TODO Auto-generated catch block
	                e.printStackTrace();
                } catch (ClassNotFoundException e) {
	                // TODO Auto-generated catch block
	                e.printStackTrace();
                }
            	
             
            }
        }, 60L, 200L);
    }
    }

    public void onDisable(){
        try {
            log.info("|| MBroker disabled! ||");
            log.info("|| DB connection Closed!||");
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            System.out.println("Error closing database!");
         }
    }

    public void onPlayerJoin(PlayerJoinEvent event){
        Player p = event.getPlayer();


        this.getServer().broadcastMessage("Welkom" + p.getName() + ".");


    }

    public void connectDB() throws SQLException, ClassNotFoundException, IOException {
        	File f = new File("msg.db3");
        	if (!f.exists()){
        		f.createNewFile();
        	}else{
        	

	        log.info("DB Connection made");
        	} 

      

    }
}





If i only have one record it print's it out but two or more I get the above error.

Anybody sees why?

Thanks!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1