- This topic has 32 replies, 4 voices, and was last updated 19 years, 2 months ago by
Haris Peco.
-
AuthorPosts
-
Haris PecoMemberetienneg,
Can you try one test before release 4.1.1 – if test add we will more chance that it will worked for your environment
You have to add junit jar and 3 jars from db2 : db2java.zip db2jcc.jar and license jar for your OS
Execute test with Run-Junit test
It is important that test (2) add without exception
Test is laterBest
import java.lang.reflect.InvocationTargetException; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.Driver; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Properties; import junit.framework.TestCase; public class Db2Type2DriverTest extends TestCase { private String driverName = "COM.ibm.db2.jdbc.app.DB2Driver"; //private String driverName = // "com.ibm.db2.jcc.DB2Driver"; private String url = "jdbc:db2:YOUR_DATABASE"; private String username = "YOU_USERNAME"; private String password = "YOUR_PASSWORD"; private static Driver driver; public Db2Type2DriverTest(String name) { super(name); if (driver == null) { try { driver = (Driver) Class.forName(driverName).newInstance(); } catch (Exception e) { e.printStackTrace(); } } } protected void setUp() throws Exception { super.setUp(); } protected void tearDown() throws Exception { super.tearDown(); } // grab schemas in main thread - work fine public void testType2InMainThread() { Connection connection = null; try { connection = getConnection(); getSchemasForTest(connection); } catch (SQLException e) { e.printStackTrace(); fail(); } finally { try { if (connection != null) connection.close(); } catch (SQLException e) {} } } public void testType2InSeparateThread() throws InterruptedException, InvocationTargetException { Connection connection = null; try { connection = getConnectionInThread(); getSchemasForTest(connection); } catch (SQLException e) { e.printStackTrace(); fail(); } finally { try { if (connection != null) connection.close(); } catch (SQLException e) {} } } private void getSchemasForTest(Connection connection) throws SQLException { DatabaseMetaData md = connection.getMetaData(); ResultSet schemas = md.getSchemas(); //while (schemas.next()) { //String schema = schemas.getString("TABLE_SCHEM"); //System.out.println(schema); //} } public Connection getConnection() throws SQLException { //String nodeNumber="0"; Properties props = new Properties(); //props.setProperty("CONNECTNODE", nodeNumber); props.setProperty("user", username); props.setProperty("password", password); //System.out.println("url=" + url); //System.out.println("props=\n" + props); return DriverManager.getConnection(url, props); } private class Connect implements Runnable { private Connection connection; public void run() { Properties props = new Properties(); props.setProperty("user", username); props.setProperty("password", password); try { connection = DriverManager.getConnection(url, props); // this is fine getSchemasForTest(connection); } catch (SQLException e) { e.printStackTrace(); } } public Connection getConnection() { return connection; } } private Connection getConnectionInThread() throws InvocationTargetException, InterruptedException { Connect connect = new Connect(); Thread connectThread = new Thread(connect, "ConnectThread"); connectThread.start(); // just wait thread while (connectThread.isAlive()) { Thread.sleep(250); } // this way work fine, but it isn't possible always /*try { connectThread.join(); } catch (InterruptedException e) { throw new InvocationTargetException(e); }*/ return connect.getConnection(); } }
markschechterMemberI had this problem also. Turns out the MyEclipse URL pattern is wrong. It is not jdbc:db2//localhost:<port>/<dbname>. It should be jdbc:db2://localhost:<port>/<dbname>. Note the colon after the “db2” !
Haris PecoMemberMark,
Your url is type 4 and it work fine in MyEclipse 4.1 – problem is type 2 (url jdbc:db2:DATABASE) and it will work in 4.1.1
Best
-
AuthorPosts