Created
August 28, 2013 09:49
-
-
Save jasononeil/6364241 to your computer and use it in GitHub Desktop.
Attempt to implement a MySQL class for Haxe Java based on waneck's branch: https://github.com/waneck/haxe/tree/java-sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sys.db; | |
@:coreApi class Mysql { | |
static var init = false; | |
/** | |
Opens a new MySQL connection on the specified path. | |
Note that you will need a MySQL JDBC driver. | |
"socket" option currently not supported | |
If port is null, 3306 is assumed. | |
**/ | |
public static function connect( params : { | |
host : String, | |
?port : Int, | |
user : String, | |
pass : String, | |
?socket : String, | |
database : String | |
} ) : sys.db.Connection { | |
if ( params.port == null ) params.port = 3306; | |
if (!init) | |
{ | |
try java.lang.Class.forName("org.sqlite.JDBC") catch(e:Dynamic) throw e; | |
init = true; | |
} | |
try | |
{ | |
var cnxString = 'jdbc:mysql://${params.host}:${params.port}/${params.database}'; | |
var properties = new java.util.Properties(); | |
properties.put("user", params.user); | |
properties.put("password", params.pass); | |
var cnx = java.sql.DriverManager.getConnection(cnxString, properties); | |
return java.db.Jdbc.create(cnx); | |
return null; | |
} catch(e:Dynamic) throw e; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment