Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does the getMaxRowSize always return 0 in session bean

Status
Not open for further replies.

IPOz

Programmer
Jul 11, 2001
109
CN
Hi,friends
I have downloades M$ JDBC driver for SQL Serve 2000. And i used the following simple program to test it:

import java.sql.*;

public class DbTest {

public static void main(String[] args)
{
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String sConnStr = "jdbc:microsoft:sqlserver://192.168.1.129:1433";

Connection conn;
ResultSet rs;
Statement stmt;

try {
Class.forName(sDBDriver);
conn = DriverManager.getConnection(sConnStr,"ihpms","ihpms");
System.out.println("row size=" + conn.getMetaData().getMaxRowSize());

while(rs.next()) {
System.out.println(rs.getString(1) + "\t" + rs.getString(2));
}

if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
if(conn != null)
conn.close();

}
catch(Exception ex) {
}
}
}
The getMaxRowSize() returns 8060.So i am sure the JDBC driver works fine.However when i use it in Session bean as below,it always returns 0 :(

import javax.ejb.*;
import javax.transaction.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;

public class BMTTestBean implements SessionBean
{
private SessionContext sessionContext;
private UserTransaction ut;
private DataSource ds;

public void ejbCreate() throws CreateException
{
}

public void ejbRemove()
{
}

public void ejbActivate()
{
}

public void ejbPassivate()
{
}

public void setSessionContext(SessionContext context)
{
sessionContext = context;
}

public void testOne()
{
Connection con = null;
PreparedStatement stmt = null;

StringBuffer sbf1 = new StringBuffer("Insert into xz_doc_type(doc_type_id, doc_type_name) values (1,'Robin Paul')");
try {
con = getConnection();
if(con != null)
System.out.println("row size=" + con.getMetaData().getMaxRowSize());
else
System.out.println("no connection");
stmt = con.prepareStatement(sbf1.toString());
sbf1 = null;
stmt.executeUpdate();
stmt.close();
}
catch( Exception se ) {
System.out.println(se.getMessage());
// se.printStackTrace();
}
}

private Connection getConnection() throws Exception
{
InitialContext initCtx = null;
initCtx = new InitialContext();
ds = (javax.sql.DataSource) initCtx.lookup("java:comp/env/jdbc/SQLServerPool");
initCtx.close();
return ds.getConnection();
}
}
I am frustrted now.Hope get help from all of you!

Thanks in advance!

IPO_z@cmmail.com
Garbage in,Garbage out
 
I assume your application server does not serve you with direct connections to your DB but from a connection pool. The actual connection you are working with may not support all JDBC features. Look for connection pooling in your application server's documentation or post additional information about your application server.
 
Thanks for your relply!
I made a low level mistake because i used a wrong JNDI name:
...
ds = (javax.sql.DataSource) initCtx.lookup("java:comp/env/jdbc/SQLServerPool");
....

I used JBoss as application server.The jboss.xml is as below:
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<jboss>
<enterprise-beans>
<session>
<ejb-name>BMTTestBean</ejb-name>
<jndi-name>ejb.BMTTest</jndi-name>
<reference-descriptor>
<resource-description>
<res-ref-name>jdbc/SQLServerPool</res-ref-name>
<jndi-name>java:/SQLServerPool</jndi-name>
</resource-description>
</reference-descriptor>
</session>
</enterprise-beans>
</jboss>
So the JNDI name should be java:/SQLServerPool! I changed it and it works now :)

Best Regards!
IPO_z@cmmail.com
Garbage in,Garbage out
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top