18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
how to connect db2
Hi,
Can u please suggest me how to write a connecting string for db2.
i just wanted to select a data from db2 table for doing some manipulation.
Regards,
praveen
Can u please suggest me how to write a connecting string for db2.
i just wanted to select a data from db2 table for doing some manipulation.
Regards,
praveen
Tagged:
This discussion has been closed.
Comments
Driver={IBM DB2 ODBC DRIVER};Database=myDataBase;Hostname=myServerAddress;Port=1234; Protocol=TCPIP;Uid=myUsername;Pwd=myPassword;
Hope this link helps: http://www.devlist.com/ConnectionStringsPage.aspx
i tired in diffrent ways to connect the db2 like below
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:odbc://SERVER:PORTNO;databasename=demo;", "user", "passsword");
var db = _getDB("sun.jdbc.odbc.JdbcOdbcDriver","jdbc:odbc:Driver={IBM DB2 ODBC DRIVER};Database=demo;Hostname=IPADDRESS;Port=portno; Protocol=TCPIP;", "user","password");
can u please help me.
regards,
praveen
To connect to DB2, you need to get the corresponding JDBC driver and add it to Sahi's classpath.
The jdbc driver is com.ibm.db2.jcc.DB2Driver, so you would use something like
_getDB("com.ibm.db2.jcc.DB2Driver", "jdbc:db2://SERVER:PORTNO/mydatabasename", "user", "passsword");
For more details have a look at http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/rjvjcdif.htm
Regards,
Narayan
please find below errors which i am getting.
Procedure which I followed:
1. Code which I wrote on my .sah file.
var db = _getDB("com.ibm.db2.jcc.DB2Driver", "jdbc:db2://SERVER:PORT/DbNAME", "user", "password");
var $rs = db.select("select * from EMPLOYEE");
2. in Sah.bat :
SET EXT_CLASS_PATH=..\extlib\db\com.ibm.db2.jcc.DB2Driver.jar; C:\mypath\custom.jar
SET SAHI_CLASS_PATH=..\lib\sahi.jar;..\extlib\rhino\js.jar;..\extlib\apc\commons-codec-1.3.jar
java -classpath %EXT_CLASS_PATH%;%SAHI_CLASS_PATH% net.sf.sahi.Proxy
3. In the following path I have copied db2jcc.jar and db2jcc_license_cu.jar files.
C:\sahi\extlib\db
Still am getting the following Console errors:
om.ibm.db2.jcc.DB2Driver.jar
java.lang.ClassNotFoundException: com.ibm.db2.jcc.DB2Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at net.sf.sahi.util.ClassLoadHelper.getClass(ClassLoadHelper.java:23)
at net.sf.sahi.plugin.DBClient.getResult(DBClient.java:99)
at net.sf.sahi.plugin.DBClient.select(DBClient.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:24
7)
at org.mozilla.javascript.optimizer.OptRuntime.callN(OptRuntime.java:86)
at org.mozilla.javascript.gen.c3._c30(<cmd>:189)
at org.mozilla.javascript.gen.c3.call(<cmd>)
at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
at org.mozilla.javascript.gen.c4._c0(<cmd>:855)
at org.mozilla.javascript.gen.c4.call(<cmd>)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:3
98)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:306
5)
at org.mozilla.javascript.gen.c4.call(<cmd>)
at org.mozilla.javascript.gen.c4.exec(<cmd>)
at org.mozilla.javascript.Context.evaluateString(Context.java:1104)
at net.sf.sahi.rhino.ScriptRunner.run(ScriptRunner.java:105)
at java.lang.Thread.run(Unknown Source)
can u please tell me what is use of C:\mypath\custom.jar and where to find the exact com.ibm.db2.jcc.DB2Driver.
..\extlib\db\com.ibm.db2.jcc.DB2Driver.jar; C:\mypath\custom.jar
to
..\extlib\db\db2jcc.jar;..\extlib\db\ db2jcc_license_cu.jar;
please find below errors which i am getting.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.sf.sahi.command.CommandExecuter.execute(CommandExecuter.java:52)
at net.sf.sahi.LocalRequestProcessor.getLocalResponse(LocalRequestProces
sor.java:42)
at net.sf.sahi.ProxyProcessor.processLocally(ProxyProcessor.java:227)
at net.sf.sahi.ProxyProcessor.run(ProxyProcessor.java:79)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at net.sf.sahi.command.Player.hasErrors(Player.java:225)
... 9 more
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.sf.sahi.command.CommandExecuter.execute(CommandExecuter.java:52)
at net.sf.sahi.LocalRequestProcessor.getLocalResponse(LocalRequestProces
sor.java:42)
at net.sf.sahi.ProxyProcessor.processLocally(ProxyProcessor.java:227)
at net.sf.sahi.ProxyProcessor.run(ProxyProcessor.java:79)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at net.sf.sahi.playback.ScriptFactory.getScript(ScriptFactory.java:25)
at net.sf.sahi.playback.ScriptFactory.getScript(ScriptFactory.java:32)
at net.sf.sahi.command.Player.setScript(Player.java:94)
at net.sf.sahi.command.Player.resetScript(Player.java:91)
... 9 more
var db = _getDB("com.ibm.db2.jcc.DB2Driver", "jdbc:db2://server:1001/demo;","user", "password");
var $rs = db.select("select EMPNAME from EMP");
Errors i got:
com.ibm.db2.jcc.c.DisconnectException: [ibm][db2][jcc][t4][2030][11211] A commun
ication error has been detected. Communication protocol being used: TCP/IP.
Communication API being used: SOCKETS. Location where the error was detected: R
eply.fill().
Communication function detecting the error: InputStream.read(). Protocol specif
ic error codes Connection reset, *, 0. Message: Connection reset
at com.ibm.db2.jcc.a.a.a(a.java:366)
at com.ibm.db2.jcc.a.ab.b(ab.java:200)
at com.ibm.db2.jcc.a.ab.c(ab.java:237)
at com.ibm.db2.jcc.a.ab.c(ab.java:348)
at com.ibm.db2.jcc.a.ab.v(ab.java:1134)
at com.ibm.db2.jcc.a.bb.a(bb.java:42)
at com.ibm.db2.jcc.a.b.j(b.java:1254)
at com.ibm.db2.jcc.a.b.b(b.java:1128)
at com.ibm.db2.jcc.a.b.b(b.java:711)
at com.ibm.db2.jcc.a.b.a(b.java:697)
at com.ibm.db2.jcc.a.b.a(b.java:378)
at com.ibm.db2.jcc.a.b.<init>(b.java:316)
at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:174)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at net.sf.sahi.plugin.DBClient.getResult(DBClient.java:100)
at net.sf.sahi.plugin.DBClient.select(DBClient.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:24
7)
at org.mozilla.javascript.optimizer.OptRuntime.callN(OptRuntime.java:86)
at org.mozilla.javascript.gen.c5._c30(<cmd>:189)
at org.mozilla.javascript.gen.c5.call(<cmd>)
at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
at org.mozilla.javascript.gen.c6._c0(<cmd>:855)
at org.mozilla.javascript.gen.c6.call(<cmd>)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:3
98)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:306
5)
at org.mozilla.javascript.gen.c6.call(<cmd>)
at org.mozilla.javascript.gen.c6.exec(<cmd>)
at org.mozilla.javascript.Context.evaluateString(Context.java:1104)
at net.sf.sahi.rhino.ScriptRunner.run(ScriptRunner.java:105)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at com.ibm.db2.jcc.a.ab.b(ab.java:193)
... 34 more
78
Looks like you are fetching too much data. Try a sql query with a limited number of rows.
Your error shows that Sahi is able to find and use the driver. The rest of the mechanism is really between the driver and your database.
I did some googling and found this: http://database.ittoolbox.com/groups/technical-functional/db2-l/getting-comibmdb2jcccdisconnectexception-for-large-data-sets-1859696
This is what an answer in the above link says: "i had the same error, changing my database driver to type 2 from type 4 solved my problem"
Other useful links: http://www.ibm.com/developerworks/db2/library/techarticle/0203zikopoulos/0203zikopoulos.html#type2
Now I would suggest you ask your developers to help you out with this or post this in a DB2 forum.
Regards,
Narayan
Thankyou for your help.
Here is the Successfull/Complete Procedure to work with DB2
Working with Db2:
1. Copy the “db2jcc.jar” and “db2jcc_license_cu.jar” files in the C:\sahi\extlib\db
Note: db2jcc.jar, db2jcc_license_cu.jar files u can search in db2 installer server.
2. if you are using sahi.bat, open the sahi.bat and update following code Note: Sahi.bat will be available in C:\sahi\bin
3. Write the script like below to retrieve the data.
Regards,
praveen
So was the port the problem?