Showing posts with label resultset. Show all posts
Showing posts with label resultset. Show all posts

Monday, March 26, 2012

Reg JDBC MS sQLSERVer driver SP2

Hi
Has anyone used ResultSet.first(), ResultSet.beforeFirst(), ResultSet.AfterLast(), ResultSet.absolute(1) methods
in your JSP code, while connecting to SQL Server 2000, using MS SQLSERVER JDBC driver SP2 ?
I am hving problems with it., as it keeps throwing the msg, SQLSERVER 2000 driver for JDBC - unsupported mehod error for all the above calls. I am using JRUN server on DM2k MX to run my JSP.
I would appreciate your replies,
Thanks
Suma
"SumaJDBC" <anonymous@.discussions.microsoft.com> wrote in message
news:015E27EC-8BFC-49B6-96FD-669661A86912@.microsoft.com...
> Hi
> Has anyone used ResultSet.first(), ResultSet.beforeFirst(),
ResultSet.AfterLast(), ResultSet.absolute(1) methods
> in your JSP code, while connecting to SQL Server 2000, using MS SQLSERVER
JDBC driver SP2 ?
> I am hving problems with it., as it keeps throwing the msg, SQLSERVER 2000
driver for JDBC - unsupported mehod error for all the above calls. I am
using JRUN server on DM2k MX to run my JSP.
> I would appreciate your replies,
> Thanks
> Suma
What do you not understand about the error message? The calls are not
supported by the driver. In general it is best to stay away from them
anyway, simply stick to next(). It will give you optimal performance and
works on all JDBC drivers.
Silvio Bierman
|||Hi silvio
Thanks for your reply. I did use next(), but I am having wierd problem with that . I have to construct a dropdown box
, populating it from the database table values.
I connect to the DB, retrieve the required column values into the result set rs.
As I display the values , the first record is always being skipped and it is always picking up from second record onwards. Now can now U understand why I need to place rs.beforeFirst(), prior to the starting of that while loop!
or is there any other way of doing this? I am new to this , thus would appreciate an expert advice!
here's my scriptlet after (connection to the Db and populatinf the ResultSet rs (using a javabean (db) class for this )
try{
//rs.beforeFirst();
while(rs.next()) {
%><option value=<%=rs.getString("DeptName")%></option><BR><%
}
} catch (Exception e) {
msg = e.getMessage();
out.println(msg);
}
%><% db.close();%></select>
|||"SumaJDBC" <anonymous@.discussions.microsoft.com> wrote in message
news:3D950D2F-8ACE-468E-97AD-A6D33DDCC897@.microsoft.com...
> Hi silvio
> Thanks for your reply. I did use next(), but I am having wierd problem
with that . I have to construct a dropdown box
> , populating it from the database table values.
> I connect to the DB, retrieve the required column values into the result
set rs.
> As I display the values , the first record is always being skipped and it
is always picking up from second record onwards. Now can now U understand
why I need to place rs.beforeFirst(), prior to the starting of that while
loop!
> or is there any other way of doing this? I am new to this , thus would
appreciate an expert advice!
> here's my scriptlet after (connection to the Db and populatinf the
ResultSet rs (using a javabean (db) class for this )
> try{
> //rs.beforeFirst();
> while(rs.next()) {
>
> %><option value=<%=rs.getString("DeptName")%></option><BR><%
> }
> } catch (Exception e) {
> msg = e.getMessage();
> out.println(msg);
> }
> %><% db.close(); %></select>
I have heard that problem previously several times and each time it was an
error in the application code that caused the behaviour. Using
ResultSet rs = ...;
while (rs.next()) //process current row
should work always. If it doesn't something is seriously broken and the
methods you mention can;t help you. I would suggest you post some actual
code that produces the behaviour.
Silvio Bierman
|||Hi Silvio,
As U suggested I tried to look into my code for possible logical errors, but couldnt find any,. So I am posting my code below:
Thanks in advance (again) for taking time to answer my queries.
Suma
// This is DbConnection.java, the bean class for getting the DBconnection and excecuting DB related methods
package BeanClasses;
import java.sql.*;
import java.io.*;
import java.lang.*;
public class DbConnection{
String dbURL = "jdbc:microsoft:sqlserver://sql1;databaseName=DEVPurContr";
String dbDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver" ;
private Connection dbCon;
public String temp;
public String getTemp() { return temp;
}
public void setTemp (String Temp){
this.temp = Temp;
}
public DbConnection() {
super();
/*try {
connect();
} catch (Exception e) { }*/
}
public boolean connect () throws Exception { //This functionis called first get a valid connection
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver");
dbCon = DriverManager.getConnection(dbURL,"webuser","webus er3070");
}
catch (Exception e) { System.out.println(e.getMessage());
}
return true;
}
public void close() throws SQLException {
dbCon.close();
}
public ResultSet execSQL (String sql) throws SQLException { //This function is called to retrive the result set
// String (sql) is supplied at the run time, which is my select statement and the returned
// result set.
Statement s = dbCon.createStatement();
ResultSet r = s.executeQuery(sql);
return (r==null) ? null : r;
}
public int execUpdate (String sql ) throws SQLException {
Statement s = dbCon.createStatement ();
int r = s.executeUpdate (sql);
return (r==0) ? -1 : r ;
}
}
// Here's my import , where I am importing relevant java packages
<%@. page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.util.*,java.lang.*,java.io .*" errorPage="" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head>
// Heres's JSP code (relevant part )
<tr><td class="RequiredDetail" style="text-align:left;"><span style="color:white; font-size:10px; font-weight:bolder"></span>
Enter Department Name
</td><td style="text-align:right;"><select name="DeptName"><%
ResultSet rs = null;
int i;
%><%
String msg;
db.connect(); // Call to the bean
try {
rs = db.execSQL("SELECT distinct DeptName FROM tblDepartment order by DeptName" ); // call to the bean
} catch(Exception e) {
msg = e.getMessage();
}
try{
//rs.beforeFirst();
while(rs.next()) {
out.println(rs.getString("DeptName"));
%><option value=<%=rs.getString("DeptName")%></option><BR><%
}
} catch (Exception e) {
msg = e.getMessage();
out.println(msg);
}
%><% db.close();%></select></td></tr>
|||As far is I can tell from this code there is no reason for the strange
behaviour. Have you tried running it in a normal application instead of a
JSP page (I have little experience with JSPs)? Have you compared such
results with running the same query from the Query Analyzer?
Silvio Bierman
|||Hi
Yes. I have run the query (thru JDBC) on regular java compiler. I have also done it on sql analyzer. In both cases the behavior is as exepected. But in JSP, when I use MS SQL Server JDBC driver. I get this odd results.
I still fail to understand why MS JDBC driver fails to support ResultSet.beforeFirst () and ResultSet.afterLast() functions?
Suma
|||te cuento que tengo el mismo problema con ResultSet.absolute(1) methods in your JSP code, while connecting to SQL Server 2000, using MS SQLSERVER JDBC driver SP2 ?
pero se logra solucionar con el drive JnetDirect pero tienes que comprarlo yo se que esa no es la idea por favor ayudame si hallas la solucion
Gracias
************************************************** ********************
Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
|||trivadeneira@.olade.org.ec wrote:

> te cuento que tengo el mismo problema con ResultSet.absolute(1) methods in your JSP code, while connecting to SQL Server 2000, using MS SQLSERVER JDBC driver SP2 ?
> pero se logra solucionar con el drive JnetDirect pero tienes que comprarlo yo se que esa no es la idea por favor ayudame si hallas la solucion
>
> Gracias
Hola. Si un mtodo falla con el MS jdbc conductor libre,
usted debe esperar o antes de que ellos liberen a su
siguiente conductor, y esperen que sea fijado entonces,
o usted puede usar un producto comercial.
El DataDirect es el negocio que realmente hace el
JDBC conductor de MS., entonces usted debera intentar su
conductor. Esto mostrar si el siguiente conductor de
los MS ser fijado.

>
> ************************************************** ********************
> Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
> Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
|||trivadeneira@.olade.org.ec wrote:

> te cuento que tengo el mismo problema con ResultSet.absolute(1) methods in your JSP code, while connecting to SQL Server 2000, using MS SQLSERVER JDBC driver SP2 ?
> pero se logra solucionar con el drive JnetDirect pero tienes que comprarlo yo se que esa no es la idea por favor ayudame si hallas la solucion
>
> Gracias
Hola. Si un mtodo falla con el MS jdbc conductor libre,
usted debe esperar o antes de que ellos liberen a su
siguiente conductor, y esperen que sea fijado entonces,
o usted puede usar un producto comercial.
El DataDirect es el negocio que realmente hace el
JDBC conductor de MS., entonces usted debera intentar su
conductor. Esto mostrar si el siguiente conductor de
los MS ser fijado.

>
> ************************************************** ********************
> Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
> Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...

refreshRow not working

Hi
Can someone confirm that the refreshRow method on a ResultSet class does not
work and that it is a bug in the driver. I've tested the same code with
different drivers and it works ok... unless Microsoft has implemented the
functionallity different, can someone tell me what that is.....
Thanks
Carel
| Thread-Topic: refreshRow not working
| thread-index: AcUqLYcVVyNsCTdOQQKygCm51b/9Fg==
| X-WBNR-Posting-Host: 195.212.29.75
| From: "=?Utf-8?B?Q2FyZWwgZHUgdG9pdA==?="
<Careldutoit@.discussions.microsoft.com>
| Subject: refreshRow not working
| Date: Wed, 16 Mar 2005 05:39:07 -0800
| Lines: 8
| Message-ID: <D1611FB1-186E-45AD-B1F0-7F4B39D2178A@.microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.sqlserver.jdbcdriver
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.sqlserver.jdbcdriver:6758
| X-Tomcat-NG: microsoft.public.sqlserver.jdbcdriver
|
| Hi
| Can someone confirm that the refreshRow method on a ResultSet class does
not
| work and that it is a bug in the driver. I've tested the same code with
| different drivers and it works ok... unless Microsoft has implemented
the
| functionallity different, can someone tell me what that is.....
|
| Thanks
| Carel
|
Hello,
The JDBC spec says that ResultSet.refreshRow() is not supported for
ResultSet objects that are type TYPE_FORWARD_ONLY, and does nothing for
those that are type TYPE_SCROLL_INSENSITIVE. This means that it can only
be used with TYPE_SCROLL_SENSITIVE. Since the Microsoft JDBC driver does
not support scroll sensitive ResultSets, the refreshRow() method is
behaving as expected.
Carb Simien, MCSE MCDBA MCAD
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/security.
sql

Friday, March 23, 2012

Reformatting ResultSet

I'm using ADO.Net to return a set of records from a SQL Server, which I
then process to create a text stream ultimately used as the InnerHTML
property of a browser control in a C# project. Please don't ask why I'm
doing it that way. I know it's stupid, but customer requirements dictate
that it be done that way. Here's my question. Assume I get the following
return from the SQL query:
KeyType ILS KeyVal 1 <ILS F1>Somevalue</ILS F2><ILS F2>Somevalue</ILS
F2>...
KeyType PARTS KeyVal 2 <PARTS F1>Somevalue</PARTS F1><PARTS
F2>Somevalue</PARTS F2>...
KeyType ILS KeyVal 3 <ILS F1>Somevalue</ILS F2><ILS
F2>SomeSpecificvalue</ILS F2>...
After processing, this yields:
<ILS Records>
<ILS>KeyVal 1
<ILS F1>Somevalue</ILS F1>
<ILS F2>Somevalue</ILS F2>
</ILS>
<ILS match='true'>KeyVal 3
<ILS F1>Somevalue</ILS F1>
<ILS F2><b>SomeSpecificvalue</b></ILS F2>
</ILS>
</ILS Records>
<PARTS Records>
<PARTS>KeyVal 2
<PARTS F1>Somevalue</PARTS F1>
<PARTS F2>Somevalue</PARTS F2>
</PARTS>
</PARTS Records>
The result above is funneled through an XML stylesheet, which renders
exactly the way the customer wants it to. There are a whole lot of ifs,
ands, and buts associated with how each record is formatted, its weight, its
type, its priority, query parameters, etc.. The SQL Server returns the
result set into the datareader object very quickly. Does it make sense to
put the application specific formatting logic into stored procedures, or
would it make more sense to leave the record level formatting in the C#
code?> Does it make sense to
> put the application specific formatting logic into stored procedures, or
> would it make more sense to leave the record level formatting in the C#
> code?
I'd leave it in c# code. TSQL isn't the best language in the world for these
types of things. I
think that your code will be more readable, manageable and efficient as c# c
ode.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"bigbob" <big@.bob.com> wrote in message news:eAn$3a9AFHA.1400@.TK2MSFTNGP11.phx.gbl...[color
=darkred]
> I'm using ADO.Net to return a set of records from a SQL Server, which I
> then process to create a text stream ultimately used as the InnerHTML
> property of a browser control in a C# project. Please don't ask why I'm
> doing it that way. I know it's stupid, but customer requirements dictate
> that it be done that way. Here's my question. Assume I get the following
> return from the SQL query:
> KeyType ILS KeyVal 1 <ILS F1>Somevalue</ILS F2><ILS F2>Somevalue</ILS
> F2>...
> KeyType PARTS KeyVal 2 <PARTS F1>Somevalue</PARTS F1><PARTS
> F2>Somevalue</PARTS F2>...
> KeyType ILS KeyVal 3 <ILS F1>Somevalue</ILS F2><ILS
> F2>SomeSpecificvalue</ILS F2>...
> After processing, this yields:
> <ILS Records>
> <ILS>KeyVal 1
> <ILS F1>Somevalue</ILS F1>
> <ILS F2>Somevalue</ILS F2>
> </ILS>
> <ILS match='true'>KeyVal 3
> <ILS F1>Somevalue</ILS F1>
> <ILS F2><b>SomeSpecificvalue</b></ILS F2>
> </ILS>
> </ILS Records>
> <PARTS Records>
> <PARTS>KeyVal 2
> <PARTS F1>Somevalue</PARTS F1>
> <PARTS F2>Somevalue</PARTS F2>
> </PARTS>
> </PARTS Records>
> The result above is funneled through an XML stylesheet, which renders
> exactly the way the customer wants it to. There are a whole lot of ifs,
> ands, and buts associated with how each record is formatted, its weight, i
ts
> type, its priority, query parameters, etc.. The SQL Server returns the
> result set into the datareader object very quickly. Does it make sense to
> put the application specific formatting logic into stored procedures, or
> would it make more sense to leave the record level formatting in the C#
> code?
>[/color]|||Thanks, Tibor.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:%232FLMK%23AFHA.1188@.tk2msftngp13.phx.gbl...
> I'd leave it in c# code. TSQL isn't the best language in the world for
these types of things. I
> think that your code will be more readable, manageable and efficient as c#
code.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "bigbob" <big@.bob.com> wrote in message
news:eAn$3a9AFHA.1400@.TK2MSFTNGP11.phx.gbl...
its
to
>