hope this can help you!I am pasting the code here so that everybody can use it for their applets. Remember, an applet can open an ODBC connection only to the host, that the applet came from . ODBC Connection to other hosts can't be allowed, for security reasons. The idea here is to open an URLConnection to the host(which has a ODBC DSN to the DB Server). So, this means the DB does NOT necessarily have to be on host(or www server). I am using a IDS ODBC Connection. YOu can download an evaluation copy of it from http://www.idssoftware.com/ . If performance doesnt really matters, you can use native ODBC-JDBC bridge. Below is my code, in brief. void processQuery(){ 
try{ Class.forName("ids.sql.IDSDriver").newInstance(); 
String url="jdbc:ids://IPADDRESS:12/"; 
url+="conn?dbtype=odbc&dsn=dsn&uid=uid&pwd=pwd"; 
Connection connection=DriverManager.getConnection(url); 
Statement statement = connection.createStatement(); 
String sql=sqlStatement; 
boolean hasResults = statement.execute(sql); 
if(hasResults){ 
ResultSet result = statement.getResultSet(); 
if(statement.getMoreResults()) 
result = statement.getResultSet(); 
if(result!=null){ 
displayResults(result); 


connection.close(); 

catch(JSException jex){System.out.println("Error1:" + 
jex.getMessage()); } 
catch(Exception ex){System.out.println("Error2:" + 
ex.getMessage()); } } 
void displayResults(ResultSet r) throws 
SQLException,JSException,Exception { 
System.out.println("Into display results!!"); 
ResultSetMetaData rmeta = r.getMetaData(); 
Vector rowVector = new Vector(); 
if(type.equalsIgnoreCase("Account") == true) 
cols = 12; 
int i,numColumns=rmeta.getColumnCount(); 
for(i=1;i<=numColumns;++i) { 
if(i<numColumns) 
text+="<TD>"+rmeta.getColumnName(i)+"</TD>"; 
else 
text+="<TD>"+rmeta.getColumnName(i)+"</TD>"; 
} boolean col=true; 
while(r.next()){ 
row tempRow = new row(); 
for(i=1;i<=cols-1;++i){ 
tempRow.mysetMem(i-1,r.getString(i).trim 
()); 

rowVector.addElement(tempRow); 
} //end of while } //good luck

解决方案 »

  1.   


    I am pasting the code here so that everybody can use it for their applets. Remember, an applet can open an ODBC connection only to the host, that the applet came from . ODBC Connection to other hosts can't be allowed, for security reasons. The idea here is to open an URLConnection to the host(which has a ODBC DSN to the DB Server). So, this means the DB does NOT necessarily have to be on host(or www server). I am using a IDS ODBC Connection. YOu can download an evaluation copy of it from http://www.idssoftware.com/ . If performance doesnt really matters, you can use native ODBC-JDBC bridge. Below is my code, in brief. void processQuery(){ 
    try{ Class.forName("ids.sql.IDSDriver").newInstance(); 
    String url="jdbc:ids://IPADDRESS:12/"; 
    url+="conn?dbtype=odbc&dsn=dsn&uid=uid&pwd=pwd"; 
    Connection connection=DriverManager.getConnection(url); 
    Statement statement = connection.createStatement(); 
    String sql=sqlStatement; 
    boolean hasResults = statement.execute(sql); 
    if(hasResults){ 
    ResultSet result = statement.getResultSet(); 
    if(statement.getMoreResults()) 
    result = statement.getResultSet(); 
    if(result!=null){ 
    displayResults(result); 


    connection.close(); 

    catch(JSException jex){System.out.println("Error1:" + 
    jex.getMessage()); } 
    catch(Exception ex){System.out.println("Error2:" + 
    ex.getMessage()); } } 
    void displayResults(ResultSet r) throws 
    SQLException,JSException,Exception { 
    System.out.println("Into display results!!"); 
    ResultSetMetaData rmeta = r.getMetaData(); 
    Vector rowVector = new Vector(); 
    if(type.equalsIgnoreCase("Account") == true) 
    cols = 12; 
    int i,numColumns=rmeta.getColumnCount(); 
    for(i=1;i<=numColumns;++i) { 
    if(i<numColumns) 
    text+="<TD>"+rmeta.getColumnName(i)+"</TD>"; 
    else 
    text+="<TD>"+rmeta.getColumnName(i)+"</TD>"; 
    } boolean col=true; 
    while(r.next()){ 
    row tempRow = new row(); 
    for(i=1;i<=cols-1;++i){ 
    tempRow.mysetMem(i-1,r.getString(i).trim 
    ()); 

    rowVector.addElement(tempRow); 
    } //end of while } I am connectiong to SQLServer DB. I also tried on MSACCESS, and worked fine. The reason why I am using port:12 with the ip address is, IDSServer will be installed on port:12, usually. The code might not be syntactically correct, as I copied part of my whole program. Hope this helps, Good Luck. 
      

  2.   

    i am sorry ,i have already send it .
    sorry.hope that can help you.
      

  3.   

    thank you very much. but how to register?Trial Period 30 day?
      

  4.   

    now there are question :server must install idsserver and run 
    i want to know 
    can you connect the odbc through the jdbc driver
      

  5.   

    我现在用Servlet(JDBC-ODBC)+Applet,
    直接连接不清促,请大家关注