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 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