Как вы объявляете строковые константы в C?

Вы можете использовать CallableStatement

String sql="begin ? := aaaa.fucntion(?,?); end;";
CallableStatement stmt = connection.prepareCall(sql);
stmt.registerOutParameter(1, OracleTypes.BOOLEAN);
stmt.setInt(2, number);
stmt.setTimestamp(3, date);
stmt.execute();

. После этого вы можете прочитать возвращаемое значение с помощью:

stmt.getBoolean(1)
60
задан 16 September 2009 в 07:56
поделиться

3 ответа

There's one more (at least) road to Rome:

static const char HELLO3[] = "Howdy";

(static — optional — is to prevent it from conflicting with other files). I'd prefer this one over const char*, because then you'll be able to use sizeof(HELLO3) and therefore you don't have to postpone till runtime what you can do at compile time.

The define has an advantage of compile-time concatenation, though (think HELLO ", World!") and you can sizeof(HELLO) as well.

But then you can also prefer const char* and use it across multiple files, which would save you a morsel of memory.

In short — it depends.

92
ответ дан 24 November 2019 в 17:11
поделиться

Одно преимущество (хотя и очень небольшое) определения строки константы в том, что вы можете объединить их:

#define HELLO "hello"
#define WORLD "world"

puts( HELLO WORLD );

Не уверен, что это действительно преимущество, но это метод, который нельзя использовать с const char *.

19
ответ дан 24 November 2019 в 17:11
поделиться

Основным недостатком метода #define является то, что строка дублируется каждый раз, когда она используется, поэтому вы можете получить множество ее копий в исполняемом файле, что сделает его больше.

8
ответ дан 24 November 2019 в 17:11
поделиться
Другие вопросы по тегам:

Похожие вопросы: