Re: PreparedStatement.setXXX
От | sumit shah |
---|---|
Тема | Re: PreparedStatement.setXXX |
Дата | |
Msg-id | 2729829C-2B72-43A0-A6E3-CCCABE5465F6@ucla.edu обсуждение исходный текст |
Ответ на | Re: PreparedStatement.setXXX (Dave Cramer <pg@fastcrypt.com>) |
Список | pgsql-jdbc |
Roberta:
Here is my utility code that implements java.sql.Array:
public static Array convertStringToPgSqlArray(final String[] s) throws Exception {
if(s == null || s.length < 1) return null;
Array a = new Array() {
public String getBaseTypeName() {return "text";}
public int getBaseType() {return 0;}
public Object getArray() {return null;}
public Object getArray(Map<String, Class<?>> map) {return null;}
public Object getArray(long index, int count) {return null;}
public Object getArray(long index, int count, Map<String, Class<?>> map) {return null;}
public ResultSet getResultSet() {return null;}
public ResultSet getResultSet(Map<String, Class<?>> map) {return null;}
public ResultSet getResultSet(long index, int count) {return null;}
public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) {return null;}
public String toString() {
String p = "{";
if(s.length == 0) {
} else {
for(int i = 0; i < s.length - 1; i++) p += s[i] + ",";
p += "'" + s[s.length - 1] + "'";
}
p+="}";
return p;
}
};
return a;
}
public static Array convertIntegerToPgSqlArray(final int[] p) {
if(p == null || p.length < 1) return null;
Array a = new Array() {
public String getBaseTypeName() {return "int4";}
public int getBaseType() {return 0;}
public Object getArray() {return null;}
public Object getArray(Map<String, Class<?>> map) {return null;}
public Object getArray(long index, int count) {return null;}
public Object getArray(long index, int count, Map<String, Class<?>> map) {return null;}
public ResultSet getResultSet() {return null;}
public ResultSet getResultSet(Map<String, Class<?>> map) {return null;}
public ResultSet getResultSet(long index, int count) {return null;}
public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) {return null;}
public String toString() {
String fp = "{";
if(p.length == 0) {
} else {
for(int i = 0; i < p.length - 1; i++) fp += p[i] + ",";
fp += p[p.length - 1];
}
fp+="}";
return fp;
}
};
return a;
}
On Jul 18, 2005, at 6:52 AM, Dave Cramer wrote:
Roberta,You can force version 2 protocol with protocolVersion=2or you can implement the Array interface.For putting information into the db, I would imagine all you need to implement is everything up to getResultSet()DaveOn 18-Jul-05, at 7:55 AM, Roberta Campo wrote:We're moving from Postgresql7.4 to v.8.0.3,with some problems rising from the strictness of the new driverpostgresql-8.0-311.jdbc3.jar.We used to call a function f(integer[]) usingPreparedStatement.setString('{...}')but now the types are not compatible.How should we fix that ?A. Using the setArray method :This requires the implementation of the interface java.sql.Array :- which methods are required in this case ?- is there any available implementation of this class ? :)B. Using the setObject(colnumber, String, type ) method :This should require less implementation than the Array, shouldn't it ?- how to specify the type int[] ?C. Using different drivers / protocol versions / ...Thanks,Roberta---------------------------(end of broadcast)---------------------------TIP 6: explain analyze is your friend
В списке pgsql-jdbc по дате отправления: