Skip to content

Instantly share code, notes, and snippets.

@jasononeil
Created August 28, 2013 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasononeil/6364241 to your computer and use it in GitHub Desktop.
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
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