Connect BigSQL using python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Connect BigSQL using python (/thread-3194.html) |
Connect BigSQL using python - Learner_Python - May-04-2017 Hello I have to connect & retrieve data from BigSQL using python.I have written a java code for doing that & I'm invoking my java code from python. My java code is following 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(); } } }The python code which I'm using to invoke my java code is [code]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")[/code]My python code is running successfully without any error.But I'm not able to get the output of Java in my python console. Can you please help me? RE: Connect BigSQL using python - Larz60+ - May-04-2017 It's SQL, so it must be in a RDBMS. I don't know of any 'Real' RDBMS that works only in Java. I don't know of an actual SQL language named BigSQL. Here's what the website BigSQL.org recommends on their home page: Quote:Postgres by BigSQL RE: Connect BigSQL using python - volcano63 - May-04-2017 See here - check_call gives you return code, use check_output (and next time, please, format your code properly )
|