2011-09-07 55 views
-2
android to oracle db: 

public class OracleActivity extends Activity{ 
private Connection con; 
protected void OnCreate(Bundle savedInstanceState){ 
super.onCreate(savedInstanceState); 
try{ 
connector(); 
} 
catch(Exception e){ 
System.out.println("not connected"+e);} 
public void Connector() throws ClassNotFoundException{ 
try{ 
Class.forName("oracle.jdbc.driver.OracleDriver"); 
System.out.println("oracle jdbc driver loaded ok."); 
con=DriverManager.getConnection("jdbc:oracle:thin:karthi/[email protected]:1521:biodata"); 
system.out.println("connected to [email protected]"); 
con.close(); 
system.out.println("sucessfully connected"); 
} 
catch(SQLException e){ 
System.out.println("not connect oracle db"+e);} 
} 
} 

am also add ojdbc14.jar file and and user-permission: added 
Failed resolving Loracle/jdbc/xa/OracleXAResource; interface 265 'Ljavax/transaction/xa/XAResource;' 
+2

你的問題是什麼? –

+0

在那個編碼沒有連接到oracle db在log_tag中顯示異常 – User

回答

0

看起來像Oracle ojdbc14.jar不包含接口javax.transaction.xa.XAResource。您還需要添加JTA JAR。你可以找到它here。順便說一下,看起來很糟糕的代碼。不一致的命名和大小寫,醜陋的語法。以下是我如何寫它:

import java.sql.Connection; 
import java.sql.DriverManager; 

public class OracleActivity extends Activity { 
    private static final String DEFAULT_DRIVER = "oracle.jdbc.driver.OracleDriver"; 
    private static final String DEFAULT_URL = "jdbc:oracle:thin:karthi/[email protected]:1521:biodata"; 
    private static final String DEFAULT_USERNAME = "scott"; 
    private static final String DEFAULT_PASSWORD = "tiger"; 

    private Connection connection; 


    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     try { 
      this.connection = createConnection(); 
     } 
     catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    public static Connection createConnection(String driver, String url, String username, String password) throws ClassNotFoundException, SQLException { 

     Class.forName(driver); 
     return DriverManager.getConnection(url, username, password); 
    } 

    public static Connection createConnection() ClassNotFoundException, SQLException { 
     return createConnection(DEFAULT_DRIVER, DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD);   
    } 
} 
+0

你沒有在你的機器上安裝Google嗎?請告訴我你需要喂什麼大小的勺子。查看上面添加的鏈接。 – duffymo

+0

如果您不斷收到ClassNotFoundException,請繼續添加JAR直到它們消失。然後,您將繼續修復您的代碼。 – duffymo

+0

忽略不具有關聯的EnclosingMethod屬性的匿名內部類 (oracle.jdbc.pool.OracleRuntimeLoadBalancingEventHandlerThread $ 1)的InnerClasses屬性。這個類可能是由acompiler生成的,它沒有針對現代.class文件格式。推薦的******表示,在上傳jta.jar ****解決方案時的期望是,使用最新的編譯器 並且不指定任何「-target」類型從源重新編譯類選項。忽略 這個警告的結果是這個類的反射操作將會被忽略 – User