我想创建一个脚本来检测和删除posgresql数据库中的公共表...
我构建的请求如下:
SELECT CONCAT('DROP TABLE ', table_schema,'.',table_name,';') AS stmt FROM information_schema.TABLES
WHERE table_schema='public' AND table_catalog='capsana'
这是我得到的输出的截图
我现在想以自动方式执行命令(在stmt列中)..而不进行复制粘贴!
有没有办法做到这一点?
答案 0 :(得分:1)
您可以使用动态SQL执行此操作;
public class AreaPrompter {
public static void main(String[] args) {
AreaPrompter prompter = new AreaPrompter();
// main method
prompter.run();
// just the triangle method
prompter.areaTriangle();
}
public void run() {
Scanner kbdln = new Scanner(System.in);
System.out.println("Welcome to the area calculating code! Which shape would you like to calculate the area of?");
System.out.println("Press 1 for a Triangle, 2 for a Circle, 3 for a Rectangle, and 0 to quit.");
int request = kbdln.nextInt();
if (request <= 0) {
System.out.println("Goodbye");
return;
} else if (request == 1) {
areaTriangle();
} else if (request == 2) {
areaCircle();
} else if (request == 3) {
areaRectangle();
}
}
public void areaTriangle() {
Scanner kbdln = new Scanner(System.in);
System.out.println("Welcome to the Tirangle area cacluator. Enter in the height of your triangle");
double triBase = kbdln.nextDouble();
}
public void areaCircle() { }
public void areaRectangle() { }
}