2010-04-08 36 views
0
package collabsoft.backlog_reports.c4; 



import java.sql.CallableStatement; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.ResultSet; 
import java.sql.ResultSetMetaData; 
import java.sql.Statement; 

//import collabsoft.backlog_reports.c4.Report; 

public class Report { 

private Connection con; 

public Report(){ 
    connectUsingJDBC(); 
} 
public static void main(String args[]){ 
    Report dc = new Report(); 
    dc.reviewMeeting(6, 8, 10); 
dc.createReport("dede",100); 
//dc.viewReport(100); 
// dc.custRent(3344,123,22,11-11-2009); 
} 

/** 
    the following method is used to connect to the database 
**/ 


public void connectUsingJDBC() { 
    // This is the name of the ODBC data source 
    String dataSourceName = "Simple_DB"; 
    try { 
    // loading the driver in the memory 
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
    // This is the connection URL 
    String dbURL = "jdbc:odbc:" + dataSourceName; 
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Collabsoft","root",""); 
    // This line is used to print the name of the driver and it would throw an exception if a problem occured 
    System.out.println("User connected using driver: " + con.getMetaData().getDriverName()); 

    //Addcustomer(con,1111,"aaa","aaa","aa","aam","111","2222","111"); 
    //rentedMovies(con); 
    //executePreparedStatement(con); 
    //executeCallableStatement(con); 
    //executeBatch(con); 

    } catch (Exception e) { 
    e.printStackTrace(); 
    } 
} 

/** 
    *this code is to link the SQL code with the java for the task 
    *as an admin I should be able to create a report of a review meeting including notes, tasks and users 
    *i will take the task id and user id and note id that will be needed to be added in the review 
    *meeting report and i will display the information related to these ida 
    **/ 




    public void reviewMeeting(int taskID, int userID, int noteID)// law el proc bt return table 
{ 
    try{ 
    CallableStatement callableStatement = con.prepareCall("{CALL report_review_meeting(?,?,?)}"); 

     callableStatement.setInt(1,taskID); 
         callableStatement.setInt(2,userID); 
         callableStatement.setInt(3,noteID); 

    ResultSet resultSet = callableStatement.executeQuery(); // or executeupdate() or updateQuery 
    ResultSetMetaData rsm = resultSet.getMetaData(); 
    int numOfColumns = rsm.getColumnCount(); 
    System.out.println("lojayna"); 

    while (resultSet.next()) 
    { 
    System.out.println("New Row:"); 
    for (int i = 1; i <= numOfColumns; i++) 
    System.out.print(rsm.getColumnName(i) + ": " + resultSet.getObject(i) + " "); 
    System.out.println(); 
    } 
    } 
    catch(Exception e) 
    { 
    System.out.println("E"); 
    } 
} 



    ////////////////////////////////// 
    ///////////////////////////////// 



    public void allproject(int projID)// law el proc bt return table 
    { 
    try{ 
    CallableStatement callableStatement = con.prepareCall("{CALL all_project(?)}"); 

      callableStatement.setInt(1,projID); 
          //callableStatement.setInt(2,userID); 
          //callableStatement.setInt(3,noteID); 

    ResultSet resultSet = callableStatement.executeQuery(); // or executeupdate() or updateQuery 
    ResultSetMetaData rsm = resultSet.getMetaData(); 
    int numOfColumns = rsm.getColumnCount(); 
    System.out.println("lojayna"); 

    while (resultSet.next()) 
    { 
     System.out.println("New Row:"); 
     for (int i = 1; i <= numOfColumns; i++) 
     System.out.print(rsm.getColumnName(i) + ": " + resultSet.getObject(i) + " "); 
     System.out.println(); 
    } 
    } 
    catch(Exception e) 
    { 
    System.out.println("E"); 
    } 
    } 














    /////////////////////////////// 












    /** 
    * here i take the event id and i take a string report and then 
    * i relate the report with the event 

    **/ 




    public void createReport(String report,int E_ID)// law el proc bt return table 
    { 
    try{ 





    Statement st = con.createStatement(); 

    st.executeUpdate("UPDATE e_vent SET e_vent.report=report WHERE e_vent.E_ID= E_ID;"); 

    /* CallableStatement callableStatement = con.prepareCall("{CALL Create_report(?,?)}"); 

      callableStatement.setString(1,report); 
          callableStatement.setInt(2,E_ID); 


    ResultSet resultSet = callableStatement.executeQuery(); // or executeupdate() or updateQuery 
    ResultSetMetaData rsm = resultSet.getMetaData(); 
    int numOfColumns = rsm.getColumnCount(); 
    System.out.println("lojayna"); 

    while (resultSet.next()) 
    { 
     System.out.println("New Row:"); 
     for (int i = 1; i <= numOfColumns; i++) 
     System.out.print(rsm.getColumnName(i) + ": " + resultSet.getObject(i) + " "); 
     System.out.println(); 
    }*/ 
    } 
    catch(Exception e) 
    { 
    System.out.println("E"); 
    System.out.println(e); 
    } 
    } 




/** 
    *in the following method i view the report of the event having the ID eventID 
    **/ 





    public void viewReport(int eventID)// law el proc bt return table 
{ 
    try{ 
    CallableStatement callableStatement = con.prepareCall("{CALL view_report(?)}"); 

     callableStatement.setInt(1,eventID); 



    ResultSet resultSet = callableStatement.executeQuery(); // or executeupdate() or updateQuery 
    ResultSetMetaData rsm = resultSet.getMetaData(); 
    int numOfColumns = rsm.getColumnCount(); 
    System.out.println("lojayna"); 

    while (resultSet.next()) 
    { 
    System.out.println("New Row:"); 
    for (int i = 1; i <= numOfColumns; i++) 
    System.out.print(rsm.getColumnName(i) + ": " + resultSet.getObject(i) + " "); 
    System.out.println(); 
    } 
    } 
    catch(Exception e) 
    { 
    System.out.println("E"); 
    } 
} 





















} 

//這些方法的結果正在控制檯上顯示,我正在使用WIKET,我希望它2在網上顯示如何完成?如何傳輸控制臺上顯示的輸出並進行格式化以使其顯示在網頁上?

+4

你應該格式化你的代碼。 – LB40 2010-04-08 17:53:05

+1

讓你的問題更簡潔,更簡潔,如果你想讓它被閱讀。 – 2010-04-08 17:56:26

+3

請閱讀http://catb.org/esr/faqs/smart-questions.html和http://sscce.org,並注意留言格式。查看常見問題的詳細信息,並使用消息預覽(在消息編輯器的底部)來驗證是否有任何內容是正確的。現在它看起來像一個無私的copy'n'paste行動,沒有任何你的身邊努力。事實上,在論壇和QA網站上,你可以儘可能多的努力回到你自己... – BalusC 2010-04-08 17:59:18

回答

0

如果你想簡單的解決方案與詹姆斯的回答去。但是,如果您需要在應用程序甚至平臺之間異步傳輸數據(當它們不在本地時進行雙倍數據傳輸),您可能需要查看JMS api(當您使用Glassfish作爲應用程序服務器時,它非常容易,或者Apache ActiveMQ實現工作良好)。我在從webapp調用系統程序/腳本的部署中使用它,然後這些程序在完成時通過JMS報告回webapp。

或者,您也可以將該輸出轉儲到數據庫。

相關問題