答案 0 :(得分:0)
创建启动重定向标准输入和标准错误的命令提示符的进程
然后将命令写入标准输入,如下所示
p.standardinput.writeline(" adb命令到这里"); 当命令完成或使用异步读取标准错误或输出以获取您返回的信息时
答案 1 :(得分:-1)
是的,好问题!查看ConnectionManager的此代码!它使用所谓的Singleton模式,其中ConstructionManager
对象的唯一构造函数是private
。您使用getInstance
方法来获取数据库连接的实例。如果已存在连接实例,则只返回已存在的Connection
。否则,它继续并构建一个新的。这样,你只需要第一次连接。
public class ConnectionManager {
private static ConnectionManager instance = null;
private final String USERNAME = "corbin";
private final String PASSWORD = "letmein";
private final String CONNECTION = "jdbc:hsqldb:file:C:\\Users\\Corbin\\Java Proj\\TaskTracker\\Kurafuto\\db";
private Connection conn = null;
private ConnectionManager() {
}
public static ConnectionManager getInstance() {
if (instance == null) {
instance = new ConnectionManager();
}
return instance;
}
private boolean openConnection() {
try {
conn = DriverManager.getConnection(CONNECTION, USERNAME, PASSWORD);
System.out.println("Connection Opened!");
return true;
} catch (SQLException e) {
System.err.println(e);
return false;
}
}
public Connection getConnection() {
if (conn == null) {
if (openConnection()) {
return conn;
} else {
return null;
}
}
return conn;
}
public void close() {
System.out.println("Closing connection...");
try {
conn.close();
conn = null;
} catch (Exception e) {
}
}
}
使用Connection
ConnectionManager.getInstance().getConnection();