From: Sells, F. <fr...@ad...> - 2004-09-24 00:51:07
|
here are two snippets (not related) that show standard jdbc stuff I use. from java.lang import Class from java.sql import * #jdbc:mysql://[host:port],[host:port].../[database] # [?propertyName1][=propertyValue1] # [&propertyName2][=propertyValue2]... # [?user=monty&password=greatsqldb] DRIVER = "com.mysql.jdbc.Driver" DBURL = "jdbc:mysql://" class JdbcTools: def __init__(self, server=""): self.Connection = None self.Server = server Class.forName(DRIVER).newInstance(); def getConnection(self, database="", user=None, password=None): url = ""+DBURL url += self.Server +"/"+database if user: url += "?user="+user+"&password="+password connection = DriverManager.getConnection(url) return connection class DataRecord: def __init__ ( self, rs ): #std constructor __init__(self, ... meta = rs.getMetaData ( ) for col in range ( 1, meta.getColumnCount( ) + 1): name = meta.getColumnName ( col ) setattr(self, string.lower ( name ), rs.getString ( col ) ) S = DriverManager.getConnection(DbUrl, user, pword).createStatement() rs = S.executeQuery("SELECT * FROM sometable") while ( rs.next( ) ): record = DataRecord ( rs ) print record.id, record.fname -----Original Message----- From: chai ang [mailto:cha...@tt...] Sent: Wednesday, September 08, 2004 7:10 PM To: jyt...@li... Cc: ca...@li... Subject: [Jython-users] Re: Oracle examples Importance: Low On Wed, 25 Aug 2004 22:44:42 -0400, Robert <ca...@li...> wrote: > Are there any examples of using Jython to connect to an > Oracle (or any > database) using JDBC? In case this might be of use.... Of course, in this case u'd need the jdbc thin driver. I think u can get one from Oracle? Regards, Chai ps is there any policy against HTML mail? There should be. #--- cut here from java.lang import Class from java.sql import Connection from java.sql import Driver from java.sql import DriverManager Class.forName( "oracle.jdbc.driver.OracleDriver" ) url = "jdbc:oracle:thin:@yourDbServerName:1521:yourDbName" user = "yourUserName" # f***, not case sensitive passw = "yourPassword" con = DriverManager.getConnection(url, user,passw) stt = con.createStatement() query = "SELECT column1 FROM myTable" print "Exec'ing query", query rs = stt.executeQuery(query) while rs.next() == 1 : print rs.getString(1) ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php _______________________________________________ Jython-users mailing list Jyt...@li... https://lists.sourceforge.net/lists/listinfo/jython-users |