Solved SQLite with SQLibrary problem

Discussion in 'Plugin Development' started by kmccmk9, Jun 21, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    kmccmk9

    Hello, I'm trying to implement SQLite and I'm using the SQLibrary. However I am trying to write the contstructor, but it returns an error. With all lines off code as seen below, it says the semicolan on line 2 should be a comma. Without line three, everything is fine. What am I doing wrong?

    Code:java
    1. //Variables
    2. Server server;
    3. Database sql;
    4. sql = new SQLite(Logger.getLogger("Minecraft"), "[HDSkinner] ", this.getDataFolder().getAbsolutePath(), "HDSkinner", ".sqlite");
     
  2. Offline

    LucasEmanuel

    Wee need the entire code. It's probably your IDE that's glitching up because something above that line is not as it should.
     
  3. Offline

    kmccmk9


    No problem. Here is the full code:
    Code:java
    1. package com.kmccmk9.HDSkinner;
    2.  
    3. import lib.PatPeter.SQLibrary.Database;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Server;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.getspout.spoutapi.SpoutManager;
    12. import org.getspout.spoutapi.player.SpoutPlayer;
    13.  
    14. public class HDSkinner extends JavaPlugin {
    15. //Variables
    16. Server server;
    17. Database sql;
    18. sql = new SQLite(Logger.getLogger("Minecraft"), "[HDSkinner] ", this.getDataFolder().getAbsolutePath(), "HDSkinner", ".sqlite");
    19.  
    20. public void onDisable()
    21. {
    22. System.out.print("HDSkinner is disabled");
    23. }
    24.  
    25. public void onEnable()
    26. {
    27. System.out.print("HDSkinner is enabled");
    28. server = this.getServer();
    29. }
    30.  
    31. public boolean onCommand(CommandSender sender,Command command, String commandLabel,String args[])
    32. {
    33. if (sender instanceof Player)
    34. {
    35. Player player = (Player) sender;
    36. SpoutPlayer splayer = SpoutManager.getPlayer(player);
    37. if(commandLabel.equalsIgnoreCase("skin"))
    38. {
    39. if (args.length == 1)
    40. {
    41. if (args[0].equalsIgnoreCase("help"))
    42. {
    43. player.sendMessage(ChatColor.BLUE + "Type the command skin followed by the url to change your skin to that url.");
    44. }
    45. else
    46. {
    47. splayer.setSkin(args[0]);
    48. }
    49. }
    50. else
    51. {
    52. player.sendMessage(ChatColor.DARK_RED + "Arguments mismatch. Type the skin command followed by help.");
    53. }
    54. }
    55. if(commandLabel.equalsIgnoreCase("cape"))
    56. {
    57. if (args.length == 1)
    58. {
    59. if (args[0].equalsIgnoreCase("help"))
    60. {
    61. player.sendMessage(ChatColor.BLUE + "Type the command cape followed by the url to change your cape to that url.");
    62. }
    63. else
    64. {
    65. splayer.setCape(args[0]);
    66. }
    67. }
    68. else
    69. {
    70. player.sendMessage(ChatColor.DARK_RED + "Arguments mismatch. Type the cape command followed by help.");
    71. }
    72. }
    73. }
    74. return true;
    75. }
    76.  
    77. }
    78.  
     
  4. Offline

    ProtoTempus

    Why save Server you can access it anywhere in you main method with getServer(). No need to save it as a variable.
    Do you mean your plugin??
    Code:java
    1. Server server;
    2. //To
    3. HDSkinner plugin;
     
  5. Offline

    kmccmk9

    ProtoTempus
    Okay I will remove that. What is your question about? Also removing that line of code did not fix the syntax error.
     
  6. Offline

    kmccmk9

    Anyone have any ideas? I still can't seem to fix this error.




    Have you been able to figure anything out?
     
  7. Offline

    Wingzzz

    kmccmk9
    You can't initialize it outside of a declaration, a method, an instance block, or a static block.

    Move it into one of those and you'll be golden.
     
  8. Offline

    kmccmk9


    Okay I tried moving it into the onCommand but it still can't be resolved.
     
  9. Offline

    Wingzzz

    Just put it in your onEnable().. Also, paste error or screenshot please?
     
  10. Offline

    kmccmk9

    I tried that as well. The error in Eclipse is; SQLite can not be resolved to a type.
     
  11. Offline

    theguynextdoor

    You need to import SQLite
     
    kmccmk9 likes this.
  12. Offline

    kmccmk9

    Ah thank you. I had an import but not the right one. This was the correct code:

    Code:
    import lib.PatPeter.SQLibrary.*;
    Does anyone know how to use this library that could lend a hand?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  13. Offline

    Wingzzz

    Ah well I had no idea you were using PatPeter's library xD
     
  14. Offline

    AmShaegar

    First of all, you cannot do this outside of a method:
    Code:
    sql = new ...
    It has to be inside your onEnable().
     
  15. Offline

    Wingzzz

    A few posts up... Also this is marked as solved.
     
  16. Offline

    AmShaegar

    Sorry, seems like I've overlooked that. My apologies. :cool:
     
    Wingzzz likes this.
  17. Offline

    kmccmk9

    Would you recommend using something else?
     
  18. Offline

    AmShaegar

    PatPeter's SQLibrary is fine. Using it by myself. I created a helper class which dynamically switches between MySQL and SQLite depending on config.

    http://pastebin.com/wQ3Ju81r
     
  19. Offline

    kmccmk9

    If I private message you could you help me?
     
  20. Offline

    AmShaegar

    Why? Just ask here and maybe me or anyone else will help you.
     
  21. Offline

    kmccmk9

    Okay I couldn't find too much documentation. I created the database but how do I set the name of the table and create it
     
  22. Offline

    AmShaegar

  23. Offline

    kmccmk9

    Ya its not the SQL as much as working with the plugin and such. Like making the table with variables and stuff.
     
  24. Offline

    AmShaegar

    Well, your description sounds like: "I have problems with grammar and such. Could you help me?" This is far too common. Everything you need to know can be found in tutorials. SQL and SQLibrary. And you need some basic Java skills as well.

    If you have a specific question, ask.
     
  25. Offline

    kmccmk9

    I don't need help with java. Also there are no tutorials I could find for using his library specifically. That's where my problems are. But I think I figured out how to set and create a table in the database with variables instead of a query.
     
Thread Status:
Not open for further replies.

Share This Page