java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java
branchv_0
changeset 75 43aa4625ab7e
parent 70 02c8eaa425e8
child 80 c4635ab3a7af
equal deleted inserted replaced
74:a8444f6a54f3 75:43aa4625ab7e
   120 		}
   120 		}
   121 	}
   121 	}
   122 
   122 
   123 	private void processQueryNow() throws ConfigurationException, SQLException, FormatterException {
   123 	private void processQueryNow() throws ConfigurationException, SQLException, FormatterException {
   124 		DatabaseDefinition dd = getConfiguration().getDatabase(options.getDatabaseName());
   124 		DatabaseDefinition dd = getConfiguration().getDatabase(options.getDatabaseName());
   125 		if (dd == null) {
   125 		FormatterDefinition fd = configuration.getFormatter(options.getFormatterName());
   126 			throw new ConfigurationException("Database is not configured: " + options.getDatabaseName());
   126 		try (DatabaseConnection c = dd.connect()) {
   127 		} else {
   127 			log.log(Level.FINE, "Database connected");
   128 			FormatterDefinition fd = configuration.getFormatter(options.getFormatterName());
   128 			Formatter f = fd.getInstance(new FormatterContext(options.getOutputStream()));
   129 			if (fd == null) {
   129 			c.executeQuery(options.getSQLCommand(), f);
   130 				throw new ConfigurationException("Formatter is not configured: " + options.getFormatterName());
       
   131 			} else {
       
   132 				try (DatabaseConnection c = dd.connect()) {
       
   133 					log.log(Level.FINE, "Database connected");
       
   134 					Formatter f = fd.getInstance(new FormatterContext(options.getOutputStream()));
       
   135 					c.executeQuery(options.getSQLCommand(), f);
       
   136 				}
       
   137 			}
       
   138 		}
   130 		}
   139 	}
   131 	}
   140 
   132 
   141 	private void processPrepareBatch() {
   133 	private void processPrepareBatch() {
   142 	}
   134 	}