2012-02-02 85 views
1

我需要使用來自我的Java應用程序的sybase中的JConnect(jConn3.jar)驅動程序連接到我的SQL Anywhere 11(Sybase)數據庫。我已經嘗試了文檔,並聯繫了技術支持,但有效的幫助已經沒有:(如果有人可能知道如何使用此驅動程序連接到Crystal Reports XI,將不勝感激...幫助Java JDBC Sybase JConnect

+1

你必須給我們更多的「它不工作」。你有一些源代碼和堆棧跟蹤?把它放在這裏!你可能也想包括命令行。找出JDBC連接字符串是JDBC中最糟糕的部分。你來對地方了,但你必須給我們更多。 – 2012-02-02 06:47:23

+0

對不起,我認爲當我說「連接到我的SQL 11(Sybase)數據庫」時誤會了我的意思......我的意思是我想連接到SQL Anywhere 11數據庫,而不是MySQL數據庫,對於誤導性上下文感到抱歉。此外,我想出了類路徑部分,Thanx很多鮑勃。但是,我想問一下,是否有可能將jConn3.jar放入我的項目中(作爲庫)並在我的應用程序啓動時動態加載它?如果是這樣,我該怎麼做? – user1184416 2012-02-02 09:08:30

+0

是什麼樣的應用程序呢? Web還是獨立的? – sebastiencol 2012-02-02 11:32:57

回答

0

確保您將jconn3.jar是您的應用程序的classpath中,然後使用JDBC驅動程序如下:

try { 
     Class.forName("com.mysql.jdbc.Driver").newInstance(); 
     String url = "jdbc:mysql://localhost/coffeebreak"; 
     conn = DriverManager.getConnection(url, "username", "password"); 

     // Do your stuff 

     conn.close(); 
    } catch (Exception ex) { 
    ... 
    } 

您的評論對我的回答有助於我們遇到這樣的問題太多我們的項目中使用的瀏覽器在JSP。 。深入研究報告時出現問題 第一次打開報告時,查看器爲您的報告生成一個標識符,您必須將其存儲在會話中所以當您向下鑽取時,您可以使用此標識符。通過這種方式,您可以指出它仍然是相同的報告,查看器將使用相同的數據源。 下面是一段代碼,它應該比文字更清楚:

// Report viewer 
CrystalReportViewer crystalViewer = new CrystalReportViewer(); 

// Key to store the report source 
String reportSourceSessionKey = "anyKeyYouWant"; 
Object reportSource = null; 

// Get the report name passed in parameter 
String reportName = request.getParameter("report"); 
if (reportName != null) { 
    // Build your report 
    ReportClientDocument reportClientDoc = new ReportClientDocument(); 

    // ... 

    // Store de report source 
    reportSource = reportClientDoc.getReportSource(); 
    session.setAttribute(reportSourceSessionKey, reportSource); 

    // Close the report document 
    reportClientDoc.close(); 
} else { 
    reportSource = session.getAttribute(reportSourceSessionKey); 
} 

// Set the source of the viewer 
crystalViewer.setReportSource(reportSource); 

.... 

這解決了我們的JNDI問題。希望它能爲你做到。

+0

你好ouapdouap,謝謝你的答案:)但是,請閱讀我的熱門評論。阿斯韋爾,該網站沒有幫助我,我一直在過去3周不停地:(這個問題是,出於某種原因,當我使用ReportViewer打開一個報告,它顯示了報告中的數據而不是從數據庫更新當我說refresh()...它不做任何事情,沒有錯誤,沒有任何東西,就像它只是跳過它...但是當我試圖在查看器內刷新時,它會拋出一個JNDI名稱錯誤...我的頭髮正忙着掉出來:o ...從嘆息,哈哈 – user1184416 2012-02-02 09:12:58