MultiUser access in JDBC -odbc brigde connection throws SQL Exception

Hi Friends,

In one java class i have using four time establish the database connection. I use the JDBC-ODBC bridgedriver connectionThis below error occcur only when muliuser acces tha java class

This two error was thrown -

1. error

Connection Sql Exception java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]SQL Server does not exist or access denied" error ...

2. error

--

Connection Sql Exception java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Timeout expired

Any one Help me!................

Please , urgent..........

Thanks.

[637 byte] By [digisourcea] at [2007-11-27 2:38:12]
# 1

>Server does not exist or access denied" error

Check the URL, username and password of your connection

>Timeout expired

Your db server may be down

To sum up, you have to check if your db server is running (IP and Port for listening) and that your connection parameters are good.

post an excerpt of your code please..

java_2006a at 2007-7-12 2:59:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

I have post the coding. Apologies for codeing line is to big.

1. I have single user can execute its working well.

if go for multi-user its not working

public double spin(Hashtable hbettype,int rndno)throws Exception

{

/*************/

bet_names=hbettype.keys();

while(bet_names.hasMoreElements())

{

String check=(String)bet_names.nextElement();

System.out.println("Bet type"+check+" bet value"+hbettype.get(check));

}

System.out.println(hbettype.size());

int len=hbettype.size();

/*****Hashtables contains no of bet types . get the bet types concat in to string becuase

*we passing the query in sql server. mainly query statement bet type search and get result

**/

bet_names=hbettype.keys();

String str="";

int i=0;

while(bet_names.hasMoreElements())

{

i++;

if(i==(hbettype.size()))

{

str = str + "[" + rndno +"] ='"+(String)bet_names.nextElement()+"'";

}

else

{

str = str + "[" + rndno +"]='"+(String)bet_names.nextElement()+"' or";

}

}

System.out.println(str);

String strquery="select ["+rndno+"] from Imm_tblCasinoRouletteBetTypes where "+str;

System.out.println(strquery);

try{

Connection con=null;

Statement stmt= null;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

prourl = "jdbc:odbc:IMM_GAMELOGICS";

con = DriverManager.getConnection(prourl,"Sa","1234");

stmt=con.createStatement();

// stmt.execute(strquery);

// rs=stmt.getResultSet();

rs =stmt.executeQuery(strquery);

while(rs.next())

{

//Type casting

String rndcols=String.valueOf(rndno);

vec.addElement(rs.getString(rndcols));

//check_no[index] = rs.getString(rndcols);

//index++;

}

rs.close();

stmt.close();

// con.close();

}catch(Exception e)

{

System.out.println("1.Roulette Game Logics Bet types Exception"+e);

//try{

//fileout.write(e);

//}catch(Exception e1){}

}

finally{

if(con!=null)

{

try{

con.close();

}catch(Exception e)

{

System.out.println("1....Connection close "+e);

}

}

}

tranid = firstInseration();

System.out.println("transid"+tranid);

int index=0;

bet_names=hbettype.keys();

String st;

String ve;

System.out.println("vector"+vec);

System.out.println("Vector Size"+vec.size());

for(int v=0;v<vec.size();v++)

{

bet_names=hbettype.keys();

while(bet_names.hasMoreElements())

{

st=(String)bet_names.nextElement();

System.out.println(st+"--"+vec.get(v));// passing int

ve = String.valueOf(vec.get(v)); // no of items

if( ve.trim().equals(st.trim()) )

{

System.out.println("sdfdsfsf"+vec.get(v) );

System.out.println(ve+"vs"+st);

//"select payout from roulette_payout where bettype ='"+ve.trim()+"'"

int pays=0;

try

{

Connection con=null;

Statement stmt= null;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

prourl = "jdbc:odbc:Imm_gamelogics";

con = DriverManager.getConnection(prourl,"Sa","1234");

//con = objdbconnect.DbconImmgGamelogics();//getDbConnection("IMM_GAMELOGICS");

stmt=con.createStatement();

String strquery1="select payout from Imm_tblCasinoPayoutRoulette where BettypeID ='"+ve.trim()+"'";

System.out.println(strquery1);

//rs1=stmt1.executeQuery("select payout from roulette_payout where bettype ='B'" );

rs=stmt.executeQuery(strquery1);

// System.out.println(strquery1);

if( rs.next())

{

pays=rs.getInt("payout");

System.out.println(pays);

}

} catch(Exception e){

System.out.println("Exception in spin method "+e);

}finally{

try{

if(con!=null){

con.close();

con = null;

}/*

if(rs!=null){

rs.close();

}

if(stmt!=null){

stmt.close();

}*/

}catch(Exception e){

System.out.println("Exception in Connection closing for spincheck spin ist close ");

}

}

double betamount=0.00f;

double winamount=0.00f;

betamount =((Double)hbettype.get(st)).doubleValue();

winamount=((Double)hbettype.get(st)).doubleValue() * pays;

try

{

Connection con=null;

Statement stmt= null;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

prourl = "jdbc:odbc:IMM_TRANSACTIONS";

con = DriverManager.getConnection(prourl,"Sa","1234");

// con = objdbconnect.DbconImmTransactions();//getDbConnection("IMM_TRANSACTIONS");

stmt=con.createStatement();

int rows=0;

rows =stmt.executeUpdate("insert into Imm_tblGameDetailsRoulette values("+tranid+",'"+rndno+"','"+ve.trim()+"',"+betamount+","+ winamount+",'1')");

System.out.println("winning "+((Double)hbettype.get(st)).doubleValue());

System.out.println(hbettype.get(st));

cashout =cashout+ ((Double)hbettype.get(st)).doubleValue()* pays;

System.out.println("insdie"+cashout);

hbettype.remove(st);

//and remove the fields from Hashtable

} catch(Exception e){

System.out.println("Exception in spin method in spincheckmethod second getconnection "+e);

}finally{

try{

if(con!=null){

con.close();

con = null;

}/*

if(rs!=null){

rs.close();

}

if(stmt!=null){

stmt.close();

}*/

}catch(Exception e){

System.out.println("Exception in Connection closing for spincheck spin ist close ");

}

}

}

/* else

{

System.out.println("losing "+((Double)hbettype.get(st)).doubleValue());

if(hbettype.get(st)!=null)

{

cashin = cashin+((Double)hbettype.get(st)).doubleValue();

}

}

*/

}

}

try{

Connection con=null;

Statement stmt= null;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

prourl = "jdbc:odbc:IMM_TRANSACTIONS";

con = DriverManager.getConnection(prourl,"Sa","1234");

}catch(Exception e)

{

System.out.println("EE "+e);

}

bet_names=hbettype.keys();

while(bet_names.hasMoreElements())

{

st=(String)bet_names.nextElement();

System.out.println(hbettype.get(st));

try{

Connection con=null;

Statement stmt= null;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

prourl = "jdbc:odbc:IMM_TRANSACTIONS";

con = DriverManager.getConnection(prourl,"Sa","1234");

// // con = objdbconnect.DbconImmTransactions();//getDbConnection("IMM_TRANSACTIONS");

stmt=con.createStatement();

int rows=0;

double winamount=0.00;

double betamount=0.00;

betamount =((Double)hbettype.get(st)).doubleValue();

rows =stmt.executeUpdate("insert into Imm_tblGameDetailsRoulette values("+tranid+" ,'"+rndno+"','"+st.trim()+"',"+betamount+","+ winamount+",'0')");

}catch(Exception e1){

System.out.println("Exception in spin method in spincheck "+e1);

}

finally{

try{

if(con!=null){

con.close();

con = null;

}

}catch(Exception e){

System.out.println("Exception in Connection closing for spincheck spin 3rd close ");

}

}

cashin = cashin+((Double)hbettype.get(st)).doubleValue();

}

return cashout;

}

Thanks for your reply

please check it. ......>

digisourcea at 2007-7-12 2:59:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

It possibly has something to do with the following:

14. Is the JDBC-ODBC Bridge multi-threaded?

No. The JDBC-ODBC Bridge does not support concurrent access from different threads. The JDBC-ODBC Bridge uses synchronized methods to serialize all of the calls that it makes to ODBC. Multi-threaded Java programs may use the Bridge, but they won't get the advantages of multi-threading. In addition, deadlocks can occur between locks held in the database and the semaphore used by the Bridge. We are thinking about removing the synchronized methods in the future. They were added originally to make things simple for folks writing Java programs that use a single-threaded ODBC driver.

15. Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection?

No. You can open only one Statement object per connection when you are using the JDBC-ODBC Bridge.

Taken from:

http://java.sun.com/products/jdbc/faq.html

This is just being thrown out for consideration though, as I have not worked my way through your code, and probably will not either.

masijade.a at 2007-7-12 2:59:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
If it is SQL Server then you could use the JTDS driver which is free and available on sourceforge.net.
jschella at 2007-7-12 2:59:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
I think that if you have a SQL Server licence Microsoft has the JDBC controller for free in it's site as a support.
RobertoZozayaa at 2007-7-12 2:59:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
> I think that if you have a SQL Server licence> Microsoft has the JDBC controller for free in it's> site as a support.Reports on this site suggest that the jTDS driver is better
jschella at 2007-7-12 2:59:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
I'm actually looking at jtid based on this forum.Thanks
RobertoZozayaa at 2007-7-12 2:59:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

Hi Friends,

Thanks for Lot of response.

I have tried the JTDS driver but they driver didn't support output parameters in execute stored procedure. some RPC

Any one help me....

How use the output parameter in StoredProcedure using JTDS driver?

Is it any other driver its support multi tread access?

Please..........

digisourcea at 2007-7-12 2:59:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9

> I have tried the JTDS driver but they driver

> didn't support output parameters in execute stored

> procedure. some RPC

It seems unlikely that they don't support output parameters at all.

But your statement could be unclear.

What documentation lead you to this?

jschella at 2007-7-12 2:59:10 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...