Closed LEEMINJOO closed 4 years ago
방법 1. 자바에서 command로 python 호출 -> python db 바로 접근
자바에서 command로 python 호출 https://m.blog.naver.com/PostView.nhn?blogId=jhnyang&logNo=221407227360&proxyReferer=https%3A%2F%2Fwww.google.com%2F
python db 바로 접근 http://pythonstudy.xyz/python/article/203-MySQL-DML
// PythonExample.java
import java.io.*;
public class PythonExample{
public static void main(String args[]){
String s = null;
try{
System.out.println("This is java");
Process process = Runtime.getRuntime().exec("python test.py");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((s = stdInput.readLine()) != null){
System.out.println(s);
}
System.out.println("Success execute python in java!");
System.exit(0);
}
catch (IOException e){
e.printStackTrace();
System.exit(-1);
}
}
}
# test.py
print('Hi, I am python')
python db 바로 접근 http://pythonstudy.xyz/python/article/203-MySQL-DML
pip install PyMySQL mysqlclient==1.3.13