|
Home > Archive > SQL Server JDBC > June 2005 > Issue with CallableStatement in java class using web service
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Issue with CallableStatement in java class using web service
|
|
|
| i have this code:
package com.milsoft.mvp.persistance;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
public class DbCalls {
public String[] a = new String[9];
public DbCalls(){
super();
}
public synchronized String[] getCustomerAddresses
ByPhone(String phone) {
Connection conn = null;
boolean notTooBig = true;
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("mssql");
conn = ds.getConnection();
} catch (Exception e) {
System.out.println(e.toString());
}
try {
CallableStatement stmt = conn
.prepareCall("{? = call PROC_GET_UNIQUE_ADDR
_BYPHONE (?)}");
stmt. registerOutParameter
(1, Types.INTEGER);
stmt.setString(2, phone);
ResultSet rs = stmt.executeQuery();
int i = 0;
while (rs.next() && notTooBig){
if(i<9){
a[i] = rs.getString("billAddr1");
i++;
}
else {
notTooBig = false;
}
}
conn.close();
} catch (Exception exc) {
System.out.println(exc.toString());
}
return a;
}
}
The code slightly modified works with a jsp and does not work with a java
class running as a web service. it always returns a string array with null
values.
Any help would be greatly appreciated!
| |
| Kamil Sykora [MSFT] 2005-06-14, 11:23 am |
| Hello,
I see that you are populating the array with this code:
while (rs.next() && notTooBig){
if(i<9){
a[i] = rs.getString("billAddr1");
i++;
}
else {
notTooBig = false;
}
}
Are you sure you are entering the while loop? if rs.next() returns false,
the array will not be populated.
I'm guessing you are getting an empty result set. What exactly is different
in the two scenarios?
Thanks,
Kamil
Kamil Sykora
Microsoft Developer Support - Web Data
Please reply only to the newsgroups.
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? For information about the Strategic Technology Protection
Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/secur_ity.
--------------------
| From: "=?Utf-8?B?dGw=?=" <tl@discussions.microsoft.com>
| Subject: Issue with CallableStatement in java class using web service
| Date: Mon, 6 Jun 2005 14:08:02 -0700
| Newsgroups: microsoft.public.sqlserver.jdbcdriver
|
| i have this code:
|
| package com.milsoft.mvp.persistance;
|
| import java.sql.*;
| import javax.naming.*;
| import javax.sql.*;
|
| public class DbCalls {
| public String[] a = new String[9];
| public DbCalls(){
| super();
| }
|
| public synchronized String[] getCustomerAddresses
ByPhone(String phone) {
| Connection conn = null;
| boolean notTooBig = true;
|
| try {
| Context ctx = new InitialContext();
| DataSource ds = (DataSource) ctx.lookup("mssql");
| conn = ds.getConnection();
|
| } catch (Exception e) {
| System.out.println(e.toString());
| }
|
| try {
| CallableStatement
stmt = conn
| .prepareCall("{? = call PROC_GET_UNIQUE_ADDR
_BYPHONE (?)}");
| stmt. registerOutParameter
(1, Types.INTEGER);
| stmt.setString(2, phone);
|
| ResultSet rs = stmt.executeQuery();
|
| int i = 0;
| while (rs.next() && notTooBig){
| if(i<9){
| a[i] = rs.getString("billAddr1");
| i++;
| }
| else {
| notTooBig = false;
| }
|
| }
|
| conn.close();
| } catch (Exception exc) {
| System.out.println(exc.toString());
| }
| return a;
| }
| }
|
| The code slightly modified works with a jsp and does not work with a java
| class running as a web service. it always returns a string array with
null
| values.
|
| Any help would be greatly appreciated!
|
| |
|
| I figured it out, but thanks for the reply.
"Kamil Sykora [MSFT]" wrote:
> Hello,
>
> I see that you are populating the array with this code:
>
> while (rs.next() && notTooBig){
> if(i<9){
> a[i] = rs.getString("billAddr1");
> i++;
> }
> else {
> notTooBig = false;
> }
>
> }
>
> Are you sure you are entering the while loop? if rs.next() returns false,
> the array will not be populated.
> I'm guessing you are getting an empty result set. What exactly is different
> in the two scenarios?
>
> Thanks,
> Kamil
>
> Kamil Sykora
> Microsoft Developer Support - Web Data
>
> Please reply only to the newsgroups.
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
> Are you secure? For information about the Strategic Technology Protection
> Program and to order your FREE Security Tool Kit, please visit
> http://www.microsoft.com/securĀ_ity.
>
>
>
> --------------------
> | From: "=?Utf-8?B?dGw=?=" <tl@discussions.microsoft.com>
> | Subject: Issue with CallableStatement in java class using web service
> | Date: Mon, 6 Jun 2005 14:08:02 -0700
> | Newsgroups: microsoft.public.sqlserver.jdbcdriver
> |
> | i have this code:
> |
> | package com.milsoft.mvp.persistance;
> |
> | import java.sql.*;
> | import javax.naming.*;
> | import javax.sql.*;
> |
> | public class DbCalls {
> | public String[] a = new String[9];
> | public DbCalls(){
> | super();
> | }
> |
> | public synchronized String[] getCustomerAddresses
ByPhone(String phone) {
> | Connection conn = null;
> | boolean notTooBig = true;
> |
> | try {
> | Context ctx = new InitialContext();
> | DataSource ds = (DataSource) ctx.lookup("mssql");
> | conn = ds.getConnection();
> |
> | } catch (Exception e) {
> | System.out.println(e.toString());
> | }
> |
> | try {
> | CallableStatement
stmt = conn
> | .prepareCall("{? = call PROC_GET_UNIQUE_ADDR
_BYPHONE (?)}");
> | stmt. registerOutParameter
(1, Types.INTEGER);
> | stmt.setString(2, phone);
> |
> | ResultSet rs = stmt.executeQuery();
> |
> | int i = 0;
> | while (rs.next() && notTooBig){
> | if(i<9){
> | a[i] = rs.getString("billAddr1");
> | i++;
> | }
> | else {
> | notTooBig = false;
> | }
> |
> | }
> |
> | conn.close();
> | } catch (Exception exc) {
> | System.out.println(exc.toString());
> | }
> | return a;
> | }
> | }
> |
> | The code slightly modified works with a jsp and does not work with a java
> | class running as a web service. it always returns a string array with
> null
> | values.
> |
> | Any help would be greatly appreciated!
> |
>
>
|
|
|
|
|