我试图连接蟒蛇BigSQL.I有一个Java代码,可以连接蟒蛇BigSQL &检索BigSQL.Below数据是我的示例代码连接BigSQL通过Java
public class Hello {
public static void main(String[] args) {
try(Connection con = DriverManager.getConnection("connection details")) {
Class.forName("com.ibm.db2.jcc.DB2Driver");
Statement stmt = con.createStatement();
System.out.println("Connected to BigSQL");
ResultSet result = stmt.executeQuery("select * from table limit 10");
while (result.next()) {
//Retrieve by com_name
String com_name = result.getString(1);
//Retrieve by family
String family = result.getString(2);
//Retrieve by sci_name
String sci_name = result.getString(3);
//Retrieve by symbol
String symbol = result.getString(4);
//Retrieve by synonym
String synonym = result.getString(5);
System.out.println(com_name+":"+family+":"+sci_name+":"+symbol+":"+synonym);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我写的一个Python代码中使用我的Python
import os
import os.path,subprocess
from subprocess import STDOUT,PIPE
path='Location where my .java file is'
os.chdir(path)
def compile_java(java_file):
subprocess.check_call(['javac', java_file])
def execute_java(java_file):
java_class,ext = os.path.splitext(java_file)
cmd = ['java', java_class]
compile_java('Hello.java')
execute_java("Hello")
我的Python代码成功运行调用这个Java代码,但我无法检索
提到的java的输出你能帮我吗?
由于提前
你为什么从蟒蛇执行Java代码?你可以使用Jython或bash吗? –
实际上,根据我的项目要求,我只能使用python –
'execute_java'什么也不做......你应该在那里添加subprocess.check_call。 –