Oracle SQL connections in Groovy and its classes -


i'm new groovy , have simple class "public static void main" executes sql via sql.execute , sql.call statements using groovy.sql.sql import. i'm importing service checks security settings within existing application in oracle database. executes sql statements. question is, how people accomplish sql connections? open connection per class, ie separate sql connection within each class? or can pass sql connection info class , use same connection somehow? right have working 2 separate connections though i'm not sure if that's way accomplish or not.

if above isn't making complete sense (since i'm newbie), here sample of code. in main class open , call sql this:

//db connection def conn = new dbconnectservice()            def sql = sql.newinstance(conn.url, conn.username, conn.password, conn.driver) 

then want check security settings call security check class this:

// security check def sec = new checksecurityservice() sec.securitycheck(programname) 

the security check, after opening exact same db connection above, sql calls this:

try  {         sql.call '{call g$_security.g$_verify_password1_prd(?, ?, ?, ?)}', [$p_object, p_version, sql.varchar, sql.varchar], { p_pass, p_rol ->             p_password = p_pass             p_role = p_rol         }  

then if it's successful return main class , more sql statements such as:

sql.execute("insert test (key1, text) values (${foo}, ${text1})") 

any information on how people appreciated! thanks!

as stated doing in main thread, assume it's single threaded application. should okay reuse connection. ideally, in multithreaded applications, should work datasource , underlying connection pool instead of directly opening , closing connection in code.

here may pass same sql object or connection security checker class without creating 2 connections. , if creating 2 connection, it's not big deal (unless doing in loop, or facing performance issue)

one suggestion : insert use prepared statement syntax instead of string interpolation

sql.execute("insert test (key1, text) values (${foo}, ${text1})")

sql.execute("insert test (key1, text) values (?, ?)", [foo, text1])


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -