Get the App
SLTechnology News&Howtos  ›  Development  › 

How does Jython connect to the database

Shulou Source: shulou.com Published: 2022-06-02 07:17:19 10月03日 Update

This article will explain in detail how Jython connects to the database. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Jython is indented to determine whether it is in the same execution block.

From java.sql import * # jython loads JAVA's package from org.postgresql import Driver # jython to connect to the database: load the database driver-- you need to add the from java.lang import * def getList (): # define the function list= [] # define the array DriverManager.registerDriver (Driver ()) # load the database driver print "already load driver" # Print message con=DriverManager.getConnection ("jdbc:postgresql://10.0.0.200:5432/zhenghe") "postgres" "postgres") st=con.createStatement () rs=st.executeQuery ("select id from tuser limit 5 offset 0") while rs.next (): System.out.println (rs.getString (1)) list.append (rs.getString (1)) # add content rs.close () st.close () to the array Con.close () return list # indentation end indicates that the function is complete print "\ nprint list with jython print:" print list print "\ n" print "print list with jython for:" for i in range (len (list)): # print list print list [I] this is the end of the article on "how Jython connects to the database" Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Tags: Data database article content function array more driver good practical information article knowledge reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Linux Microsoft vpn Docker