Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

setAutoCommit(false) and Transaction Isolation

3 posts in JDBC Connect (product renamed to JConnect) Last posting was on 1997-09-02 12:52:24.0Z
Donald Ye Posted on 1997-08-13 00:35:10.0Z
Message-ID: <33F1013E.41CC@acunet.net>
Date: Tue, 12 Aug 1997 20:35:10 -0400
From: Donald Ye <Donald@acunet.net>
Reply-To: Donald@acunet.net
Organization: Salomon Bros Inc.
X-Mailer: Mozilla 3.01Gold (WinNT; I)
MIME-Version: 1.0
Subject: setAutoCommit(false) and Transaction Isolation
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 20
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:381
Article PK: 252133

Hi,

Does anyone know whether setAutoCommit(false) and Transaction Isolation
work in Sybase SQL server? I follow the instructions on July 6 fix news
by Sybase to let my sa install sql_server.sql and sp_mda in the server.
But it still keeps returning the exception message "Metadata access info
is not found in this database". Does anyone know why?

Thank you.

--

----------------------------------------------------------
Donald Ye
Salomon Bros. Inc.
7 WTC, 28th Fl.
New York, NY 10048
dy03529@imcnam.sbi.com
(212) 783-0432
----------------------------------------------------------


lim wee sin Posted on 1997-09-02 09:11:06.0Z
Message-ID: <340BD82A.6AA9@hq.singaport.gov.sg>
Date: Tue, 02 Sep 1997 17:11:06 +0800
From: lim wee sin <limws@hq.singaport.gov.sg>
X-Mailer: Mozilla 3.0 (X11; I; SunOS 5.5 sun4m)
MIME-Version: 1.0
Subject: Re: setAutoCommit(false) and Transaction Isolation
References: <33F1013E.41CC@acunet.net>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.jdbcconnect
Lines: 19
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:337
Article PK: 252088

I have the same problem here. I have installed the sql_server.sql a few
times and have even downloaded the latest version to install. Yet
everytime it reach the statement setAutoCommit(false) there will be the
exception with SQLState = JZ0SJ.

anyone know why ?
I am using SQL Server 10.0

Donald Ye wrote:
>
> Hi,
>
> Does anyone know whether setAutoCommit(false) and Transaction Isolation
> work in Sybase SQL server? I follow the instructions on July 6 fix news
> by Sybase to let my sa install sql_server.sql and sp_mda in the server.
> But it still keeps returning the exception message "Metadata access info
> is not found in this database". Does anyone know why?
>
> Thank you.
>
> --
>


Lance Andersen Posted on 1997-09-02 12:52:24.0Z
Message-ID: <340C0C08.6981@sybase.com>
Date: Tue, 02 Sep 1997 08:52:24 -0400
From: Lance Andersen <lancea@sybase.com>
X-Mailer: Mozilla 3.01Gold (X11; I; SunOS 5.5.1 sun4m)
MIME-Version: 1.0
To: lim wee sin <limws@hq.singaport.gov.sg>
CC: Donald@acunet.net
Subject: Re: setAutoCommit(false) and Transaction Isolation
References: <33F1013E.41CC@acunet.net> <340BD82A.6AA9@hq.singaport.gov.sg>
Content-Type: multipart/mixed; boundary="------------37BF519F2436"
Newsgroups: sybase.public.jdbcconnect
Lines: 278
Path: forums-1-dub!forums-master.sybase.com!forums.powersoft.com
Xref: forums-1-dub sybase.public.jdbcconnect:334
Article PK: 252087

This does work. I have attached a sample program using
setAutoCommit().

If you still have problems, please post a program that demonstrates the
problem and will compile and execute cleanly.

lim wee sin wrote:
>
> I have the same problem here. I have installed the sql_server.sql a few
> times and have even downloaded the latest version to install. Yet
> everytime it reach the statement setAutoCommit(false) there will be the
> exception with SQLState = JZ0SJ.
>
> anyone know why ?
> I am using SQL Server 10.0
>
> Donald Ye wrote:
> >
> > Hi,
> >
> > Does anyone know whether setAutoCommit(false) and Transaction Isolation
> > work in Sybase SQL server? I follow the instructions on July 6 fix news
> > by Sybase to let my sa install sql_server.sql and sp_mda in the server.
> > But it still keeps returning the exception message "Metadata access info
> > is not found in this database". Does anyone know why?
> >
> > Thank you.
> >
> > --
> >

--
===============================================================================
Lance J. Andersen Email: lancea@sybase.com
Sybase Technical Support Phone:(617) 564-6336
77 South Bedford Street Fax: (617) 564-6148
Burlington, MA 01803

The Dark Knight Returns!!! Let's Go Penguins!!!
===============================================================================

/* AutoCommit.java Sybase Product Support group, 06/01/97
* Copyright (c) 1997, Sybase., Emeryville, CA 94608
* All Rights Reserved
*
* TITLE: AutoCommit.java
*
* START-HISTORY:
*
* 01 Jun 97 edit 0 - Lance Andersen.
* Initial coding.
*
* END-HISTORY
*
* START-DESCRIPTION:
*
* AutoCommit class demonstrates how to use the Connection methods
* getAutoCommit(), setAutoCommit(), rollback() and commit().
*
* AutoCommit may be invoked with the optional parameters:
* -U username
* -P password
* -D debuglibraries
* -S server
*
*
* END-DESCRIPTION
*/

import java.io.*;
import java.sql.*;
import java.util.*;
import com.sybase.utils.Debug;

class AutoCommit {

static String _user = "sa";
static String _password = "";
static String _url = "jdbc:sybase:Tds:alder:6689/pubs2";


public static void main (String args[]) {


String createQuery = "create table committest(f1 int, f2 char(5))";
String dropQuery = "drop table committest";

// Parse the command line

if (!processCommandline(args))
{
System.out.println(
"Syntax:\n" +
"\tExecuteQuery [-U <username>] [-P <password>] " +
" [-S <servername>]\n\t\t [-D <debug-class-list>]");
System.exit(1);
}


try {

// Load the Sybase Driver


Class.forName("com.sybase.jdbc.SybDriver");


// Attempt to connect to a driver.

Connection con = DriverManager.getConnection(_url, _user, _password);

// If we were unable to connect, an exception
// would have been thrown. So, if we get here,
// we are successfully connected to the URL

// Check for, and display and warnings generated
// by the connect.

checkForWarning (con.getWarnings ());

// create our table
execDDL(con, createQuery);

// get the current commit state
System.out.println("getAutoCommit= " + con.getAutoCommit());
execTranTest(con, true);

System.out.println("Executing setAutoCommit(false) ");
con.setAutoCommit(false);

System.out.println("getAutoCommit= " + con.getAutoCommit());
execTranTest(con, false);


// reset AutoCommit
con.setAutoCommit(true);
// drop our table
execDDL(con, dropQuery);

// Close the connection

con.close();

}
catch (SQLException ex) {

// A SQLException was generated. Catch it and
// display the error information. Note that there
// could be multiple error objects chained
// together

System.out.println ("\n*** SQLException caught ***\n");

while (ex != null) {
System.out.println ("SQLState: " + ex.getSQLState ());
System.out.println ("Message: " + ex.getMessage ());
System.out.println ("Vendor: " + ex.getErrorCode ());
ex = ex.getNextException ();
System.out.println ("");
}
}
catch (java.lang.Exception ex) {

// Got some other type of exception. Dump it.

ex.printStackTrace ();
}
}
/*
* execTranTest
* Execute a series of inserts, sp_lock and select @@tranchained and
* then a commit() and rollback()
* The sp_lock output will show that we are in a chained transaction as well
* autoCommitState = true when setAutoCommit(true)
* autoCommitState = false when setAutoCommit(false)
*
*/
private static void execTranTest (Connection con, boolean autoCommitState)
throws SQLException
{
String insertQuery = "insert committest values(1, '***test***')";
String query = "select * from committtest";
String checkTranChained ="select @@tranchained";
String checkLocks = "sp_lock";

// Display the current transtate
displayRows(con, checkTranChained);


// Insert a row and display our locks
execDDL(con, insertQuery);
displayRows(con, checkLocks);

// Commit our Transaction and display our locks again
if(!autoCommitState)
{
con.commit();
displayRows(con, checkLocks);
}
// Insert a row
execDDL(con, insertQuery);
displayRows(con, checkLocks);

// Rollback our Transaction and display our locks again
if(!autoCommitState)
{
con.rollback();
displayRows(con, checkLocks);
}
}

/*
* execDDL
* Execute a DDL or a DML statement that does not return a ResultSet
*/

private static void execDDL( Connection con, String cmd) throws SQLException
{
System.out.println("Executing: " + cmd);
Statement statement = con.createStatement();
int numrows = statement.executeUpdate(cmd);
System.out.println("Number of rows affected= " + numrows);
statement.close();
}

/*
* checkForWarning
* Checks for and displays warnings. Returns true if a warning
* existed
*/

private static boolean checkForWarning (SQLWarning warn) throws SQLException
{
boolean rc = false;

// If a SQLWarning object was given, display the
// warning messages. Note that there could be
// multiple warnings chained together

if (warn != null) {
System.out.println ("\n *** Warning ***\n");
rc = true;
while (warn != null) {
System.out.println ("SQLState: " + warn.getSQLState ());
System.out.println ("Message: " + warn.getMessage ());
System.out.println ("Vendor: " + warn.getErrorCode ());
System.out.println ("");
warn = warn.getNextWarning ();
}
}
return rc;
}

/*
* displayRows
* Execute the desired DML statement and then call dispResultSet to
* display thre rows and columns
*/

private static void displayRows( Connection con, String query)
throws SQLException
{

Statement stmt = con.createStatement();;
System.out.println("Executing: " + query);

ResultSet rs = stmt.executeQuery (query);
dispResultSet(rs);

rs.close();
stmt.close();
}

/*
* processCommandline
* Parse the Command Line and set the appropriate options
*/

static private boolean processCommandline(String args[])
{
//* DONE
String arg;
int errorCount = 0;
for (int i = 0; i < args.length; i++)
{
arg = args[i];
if (arg.regionMatches(0, "-", 0, 1))
{
try
{
switch(arg.charAt(1))
{
case 'D':
i++;
try
{
Debug.debug(true, args[i]);
}
catch (IOException ioe)
{
System.out.println(
"Error turning on debugging " + ioe);
}
break;
case 'U':
i++;
_user = args[i];
break;
case 'P':
i++;
_password = args[i];
break;
case 'S':
i++;
_url = args[i];
break;
default:
System.out.println("Invalid command line option: " + arg);
errorCount++;
break;
}
}
catch (ArrayIndexOutOfBoundsException aioobe)
{
System.out.println("missing option argument");
errorCount++;
}
}
else
{
// The syntax has no non "-" arguments
errorCount++;
}
}

return(errorCount == 0);
}

/*
* dispResultSet
* Display a ResultSet. Also calls ResultSetMetaData to obtain the
* column names
*/

private static void dispResultSet (ResultSet rs) throws SQLException
{
int i;

// Get the ResultSetMetaData. This will be used for
// the column headings

ResultSetMetaData rsmd = rs.getMetaData ();

// Get the number of columns in the result set

int numCols = rsmd.getColumnCount ();

// Display column headings

for (i=1; i<=numCols; i++) {
if (i > 1) System.out.print("\t\t");
System.out.print(rsmd.getColumnLabel(i));
}
System.out.println("");

// Display data, fetching until end of the result set

while (rs.next ()) {

// Loop through each column, getting the
// column data and displaying

for (i=1; i<=numCols; i++) {
if (i > 1) System.out.print("\t\t");
System.out.print(rs.getString(i));
}
System.out.println("");

// Fetch the next result set row

}
}
}