Jump to content




[CC 1.48 - 1.5] ccDB - Connect With Real Databases

peripheral

88 replies to this topic

#21 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 30 December 2012 - 05:13 AM

Here's an updated version for MC 1.4.6
Needs at least ComputerCraft v1.481

Haven't tested it extensively yet, so I'm holding off on updating the OP.
Here you go: [attachment=837:ccMySQL_1.0.0_mc1.4.6.zip]


EDIT: Obsolete, get the latest ccDB on the OP now. :)

Edited by Espen, 20 January 2013 - 01:09 AM.


#22 iownall555

  • Members
  • 54 posts

Posted 30 December 2012 - 04:06 PM

Hmm I think the connector id is conflicting with one of the turtle ids.

Spoiler

The other peripheral mods I have installed are ccCable and Immibis Peripherals. I'll try a different block id.

#23 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 30 December 2012 - 04:09 PM

View Postiownall555, on 30 December 2012 - 04:06 PM, said:

Hmm I think the connector id is conflicting with one of the turtle ids.

Spoiler

The other peripheral mods I have installed are ccCable and Immibis Peripherals. I'll try a different block id.
Yeah, if you re-use the config from the old version, then you have to change the ID. Either for this block, or for the turtle block.

#24 iownall555

  • Members
  • 54 posts

Posted 30 December 2012 - 04:14 PM

To be honest, this is the first time I've used this mod. Nonetheless I've gotten it to work. It does look really promising though.

#25 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 30 December 2012 - 04:36 PM

Nice to hear you got it working. If you have any problems let me know.
Might be a few hours before I answer though, as it's almost 5 in the morning here and I really have to get some quality sleep. ^_^

#26 hach-que

  • New Members
  • 1 posts

Posted 02 January 2013 - 08:26 PM

Hi, is there source code available for this? I'd like to port it to PostgreSQL and add update / insert functionality.

#27 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 02 January 2013 - 11:00 PM

View Posthach-que, on 02 January 2013 - 08:26 PM, said:

Hi, is there source code available for this? I'd like to port it to PostgreSQL and add update / insert functionality.
Not at the moment, but I'm planning to as soon as I'm done with the next version and have cleaned up the code somewhat (it's an experimental mess right now).
The next version will include the possibility of connecting to any DBMS with JDBC support, not just MySQL.
That also includes PostgreSQL (Coincidentally I've been testing with that one as well). ^_^

I'm making good progress, multiple connections are working now, as well as general DBMS support.
What I'm working at now is to make work with SMP in a sensible way.

After that, the next thing on the list is adding functions for writing/manipulating data (because at the moment I've only included the possibility to read from the database).

#28 unstopablekk

  • Members
  • 50 posts

Posted 13 January 2013 - 05:13 PM

---- Minecraft Crash Report ----
// Don't be sad. I'll do better next time, I promise!
Time: 1/12/13 10:59 PM
Description: Failed to start game
cpw.mods.fml.common.LoaderException: java.lang.NoClassDefFoundError: espen/ccMySQL/connectorBlock/BlockMySQLConnector
at cpw.mods.fml.common.LoadController.transition(LoadController.java:117)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:658)
at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:207)
at net.minecraft.client.Minecraft.a(Minecraft.java:456)
at asq.a(SourceFile:56)
at net.minecraft.client.Minecraft.run(Minecraft.java:744)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: espen/ccMySQL/connectorBlock/BlockMySQLConnector
at espen.ccMySQL.shared.ccMySQLProxyCommon.registerBlocks(ccMySQLProxyCommon.java:27)
at espen.ccMySQL.shared.ccMySQLProxyCommon.load(ccMySQLProxyCommon.java:16)
at espen.ccMySQL.server.ccMySQLProxyServer.load(ccMySQLProxyServer.java:9)
at espen.ccMySQL.client.ccMySQLProxyClient.load(ccMySQLProxyClient.java:14)
at espen.ccMySQL.ccMySQL.load(ccMySQL.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:485)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)
at com.google.common.eventbus.EventBus.post(EventBus.java:268)
at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:69)
at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)
at com.google.common.eventbus.EventBus.dispatch(EventBus.java:317)
at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:300)
at com.google.common.eventbus.EventBus.post(EventBus.java:268)
at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:83)
at cpw.mods.fml.common.Loader.initializeMods(Loader.java:657)
... 5 more
Caused by: java.lang.ClassNotFoundException: espen.ccMySQL.connectorBlock.BlockMySQLConnector
at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:185)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 35 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassNotFoundException: aiq
at codechicken.nei.asm.NEITransformer.transform(NEITransformer.java:158)
at cpw.mods.fml.relauncher.RelaunchClassLoader.runTransformers(RelaunchClassLoader.java:228)
at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:173)
... 37 more
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: aiq
at codechicken.core.asm.ClassHeirachyManager.classExtends(ClassHeirachyManager.java:65)
at codechicken.core.asm.ClassHeirachyManager.classExtends(ClassHeirachyManager.java:71)
at codechicken.core.asm.ClassHeirachyManager.classExtends(ClassHeirachyManager.java:29)
at codechicken.nei.asm.NEITransformer.transformer001(NEITransformer.java:34)
at codechicken.nei.asm.NEITransformer.transform(NEITransformer.java:150)
... 39 more
Caused by: java.lang.ClassNotFoundException: aiq
at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:89)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at codechicken.core.asm.ClassHeirachyManager.classExtends(ClassHeirachyManager.java:56)
... 43 more
Im getting that error when running tekkit lite MC 1.4.7 and did not extract anything besides the java thing... Help?
I am also new at MySQL. How would this work? Can I use it locally like computerA requesting password information from computerB (This ccMySQL being computerB)
I have no clue on how to setup MySQL and I only want to use it like this:
Can I set it up like the video above but without a REAL MySQL server? If not then how can I set it up with a MySQL server?

#29 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 13 January 2013 - 11:46 PM

@unstopablekk:
There is no ccMySQL version for MC 1.4.7 yet, I think you misinterpreted the title. It says CC 1.47 (meaning ComputerCraft 1.47), not MC 1.4.7 ^_^ (Think I'm going to change that to make it more obvious in the future)
Judging from your crash report it looks like Forge can't find the classes from this mod, which either indicates that you've not put the .zip in the mods folder, or that something changed with MC 1.4.7
I haven't looked into MC 1.4.7 yet, as I am just finishing up work on the next version of this mod, so I can't tell you yet if the new MC version is a problem or not.

As to your question for how to use this mod:
If you play singleplayer, then all connections to databases are made via your computer.
If you play on a server, then all connections to databases are mode via the server.
That means the server owners either have to setup a database server for this mod or have to allow outbound connections made via this mod, or else you can't use it.

Whichever way you do it, you definitely need a real MySQL server though. That was the whole point for doing this mod.^^
It enables you to connect to a real database (via Java database drivers) and issue commands on it via ComputerCraft commands.
And yes, you can do something like in the video with a real database. But it involves a lot more steps.
You need a DBMS (MySQL in this version), create a database, create a table in this database with all the necessary fields, create a Lua program which takes input sent to it via rednet and access the database fields to check if the input matches.

If you haven't done anything like that before, then I'd suggest learning SQL first and how to setup a DBMS, as that is essential if you want to make your own database server.
If you just want to access someone else's database, then simply follow the instructions in the OP.
You need a valid username and password to the database server you're trying to connect to, of course.

I'm almost done with the new update which will change a few things.
At the moment I'm editing the OP (offline). After that I'm going to take a look at the new MC 1.4.7 and compile for it too, if it turns out to be necessary to work.

Will report back as soon as I'm done.

#30 unstopablekk

  • Members
  • 50 posts

Posted 14 January 2013 - 05:27 AM

@Espen Thanks for your reply, im extremely interested and will definitely look into MySQL setting up databases since this looks very promising.


#31 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 14 January 2013 - 10:47 AM

K, I'm finally done with the new version.
Added 2.0 beta downloads & changed the OP.

#32 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 15 January 2013 - 11:21 PM

Omg, why did nobody tell me? The Dropbox Link was still pointing to the old version! :wacko:

Fixed, it points to v2.0 beta now, sorry for any confusion. ^_^

#33 Meni

  • Members
  • 59 posts

Posted 19 January 2013 - 07:18 PM

Awesome a nice ideao would put the misc peripherals controled crafter recipes on this database.

#34 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 20 January 2013 - 02:42 PM

View PostMeni, on 19 January 2013 - 07:18 PM, said:

Awesome a nice ideao would put the misc peripherals controled crafter recipes on this database.
This mod doesn't include a database. It lets you connect to a real, outside-Minecraft database.

#35 Meni

  • Members
  • 59 posts

Posted 22 January 2013 - 05:23 PM

View Postimmibis, on 20 January 2013 - 02:42 PM, said:

View PostMeni, on 19 January 2013 - 07:18 PM, said:

Awesome a nice ideao would put the misc peripherals controled crafter recipes on this database.
This mod doesn't include a database. It lets you connect to a real, outside-Minecraft database.
Yes would be cool if some one host a database with many crafting patterns , thhat what im talking about

#36 iownall555

  • Members
  • 54 posts

Posted 23 January 2013 - 06:44 PM

In the new update, trying to connect to a database raises a "attempted to call nil" error for me.
I've tried:
sql = peripheral.wrap("left")
db = sql.connect(url, user, pass)
and
sql = peripheral.wrap("left")
db = sql.getNewConnection(url, user, pass)

Both give me the same error. I've checked if the API is leaded and it has.

Edit: Forgot to mention that I'm running Minecraft 1.4.6

#37 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 24 January 2013 - 12:30 AM

@iownall555:
Connecting doesn't work like that anymore.
The new version comes with a Lua-side API called "ccDB".
If you place down the peripheral next to a computer and start/restart the computer, then the file should exist in "rom/apis/"
(But you can also extract it from the lua-folder of the mod, put it in a specific computer and then load it via os.loadAPI() if you prefer it that way)

Using this new API, you connect like so:
db = ccDB.getNewConnection(url, user, pass)
This will create db as a database "object" (really a table).
From then on, everything you do with the db "object" will only affect that particular connection.
Keep in mind though that all database "objects" you create have to execute their functions with a colon, like this:
db:executeQuery("SELECT * FROM table")

You should only ever use the dot for calling functions on the ccDB API:
ccDB.getVersion()
ccDB.getDebug()
-- and so on...



Now if you don't want to use the API, but rather do everything yourself, then that's totally possible, albeit you have to type more.
sql = peripheral.wrap("left")
db = sql.getNewConnectionID(url, user, pass)  -- Returns a unique number to identify this particular connection. Notice the 'ID' at the end.
Since you could open multiple connections, before you execute a function on a database connection now you need to make sure to tell the peripheral on which particular connection you want to execute the command.
Like this:
sql.setCurrentConnectionID(db)  -- Tells the peripheral to set itself to the ID of 'db'
sql.executeQuery("SELECT * FROM table")
You don't have to use setCurrentConnectionID() before every command though, only whenever you want to switch to another connection.
And notice that there is no database "object" on which we call the functions. We have to do all the calls directly with the peripheral ("sql").
That's also the reason why we're not using a colon for the function calls, but a dot.
The colon is only need when using database "objects".

So as you can see, with the API I tried to relieve you from switching around connections manually and instead provide you with the convenience of connection "objects".
But it's totally up to you which method you choose.
If you want to know more specifics, take a look at the [u]General usage[u] section in the OP.

Cheers :)

#38 iownall555

  • Members
  • 54 posts

Posted 24 January 2013 - 01:12 PM

Thanks so much for the help. I think I may have gotten the API confused with the peripheral.wrap() in my last post because I made the assumption that you had used "ccDB" as an example name for the peripheral. But it is working for me now.
Thanks again. :)

#39 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 24 January 2013 - 01:29 PM

No problem at all, glad it works for you now.
If you encounter any other problems or think you've found a bug, etc. then please let me know. I always enjoy constructive feedback.
Other than that, have fun. ^_^

#40 rm_you

  • Members
  • 5 posts

Posted 24 January 2013 - 04:02 PM

I love this concept -- this is exactly what I need for one of my more ambitious in-game projects.

Unfortunately, I haven't been able to get a connection working yet. No matter what I do, I can't seem to get it to load any JDBC drivers.
I'm on Debian (Squeeze) and I've tried with Postgres and SQLite (though I have no idea if SQLite will work, since I don't think you've tested with it) to no avail. I always get this output:

[SEVERE] [ccDB] No suitable driver found for jdbc:postgres://localhost
[SEVERE] [ccDB] No suitable driver found for jdbc:sqlite:test.db

The ingame commands I've tried are:
db = ccDB.getNewConnection("jdbc:postgres://localhost", "myuser", "mypass")
db = ccDB.getNewConnection("jdbc:sqlite:test.db", "a", "a")
I'm not sure about the user/pass on the second one, since SQLite doesn't have user/pass based security...

I've tried putting the JDBC jarfiles for Postgres and SQLite in the mods/ folder (wherein Forge *says* it has injected them into the classpath).
I've tried setting the classpath / bootclasspath on the commandline when starting the server.
I've tried setting the CLASSPATH environment variable.
I've tried after installing libpg-java via apt-get (the package for the postgres JDBC jar), which should install into the global classpath on the system.

I've also tried with and without using the commandline option: -Djdbc.drivers=org.sqlite.JDBC

Nothing seems to work. Any ideas?

For reference, the SQLite driver is here: https://bitbucket.or...ial/sqlite-jdbc

Edit: HA! I found a combination that I apparently missed but does work, involving -Xbootclasspath and -Djdbc.drivers (which I am now pretty sure is case sensitive); unfortunately, SQLite looks like a no-go because of the following error:
[SEVERE] [ccDB] SQLite only supports TYPE_FORWARD_ONLY cursors

Oh well, guess I'll see if I can get Postgres working and just use that. SQLite would be really nice though if you feel like giving it a shot. :)

Edit 2: It looks like for Postgres I was formatting my URL incorrectly. It's supposed to be "jdbc:postgresql://host/db". Missed the "ql" and DB is *required*. Well, I feel dumb now. Would still love SQLite support though!

Edit 3: Connected to a Postgres database, but every query I try to run with db:executeQuery() just returns an error.
For example, I have a table named "bob":
db = ccDB.getNewConnection("jdbc:postgresql://myserver/mydb", "myuser", "mypass")
db:executeQuery("SELECT * FROM bob")
db:executeQuery("SELECT * FROM bob;")
db:executeQuery("SELECT * FROM mydb.bob")
db:executeQuery("SELECT * FROM mydb.bob;")
The db opens correctly, but then all four queries just return:
string:10: java.lang.AbstractMethodError cannot be cast to java.lang.Exception
I work with MSSQL all day at work, but I'm not super familiar with Postgres; maybe I am just doing something obviously wrong?
I tried turning on debugging, but it doesn't print anything to the server console when the queries fail. :(
It looks like even db:disconnect() causes that error (except on line 9).

Edit 4: So, looks like Debian ships with the JDBC3 version of the Postgresql lib; manually switched to the JDBC4 version and it seems to be working BETTER. Disconnect works, and the queries at least return some sort of error that looks like it's from the DB instead of Java just breaking.

Edit 5: Alright, got it working, the last issue was just me not knowing PostgreSQL syntax. So, a couple of notes for fixes to your documentation:

You list an example connection string using "jdbc:postgres". That is incorrect -- it's "jdbc:postgresql". Also, the database is *required* in the connection string for Postgres, I suppose possibly unlike MySQL.
For the java commandline, you have the -Xbootclasspath completely inside quotes, which doesn't work. It needs to be unquoted.
Here's my java commandline:
java -Xmx1G -Xms1G -Xbootclasspath/a:/home/adam/tekkit-lite/postgresql.jar -Djdbc.drivers=org.postgresql.Driver -jar TekkitLite.jar nogui

So, you can ignore almost everything I said, but I'll leave it here just in case someone else has a similar issue so they don't have to blindly stumble through it like I did. :P





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users