0

这是我的代码,我正在尝试使用 jtds1.2.5 驱动程序连接到 sqlserver 2000,但我在 android 中发现类未找到异常

我已将驱动程序添加到构建路径中,但它仍然显示 classnot found 异常

我将 jtds jar 文件添加到构建路径中,如下所示

projrct->properties->java buildpath->添加外部jar->jtds.jar

我的代码是

包 com.sqlconnect.pack;

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

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import net.sourceforge.jtds.jdbc.Driver;

public class SqlconnectActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.i("Android","SQLConnection");
        Connection con=null;
        try{

           // Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
            //jdbc:microsoftsqlserver
            con=DriverManager.getConnection("jdbc:jtds:sqlserver://10.0.2.2:1433/Master","sa","sa");
            Log.w("Connection","open");



            Statement st=con.createStatement();
            ResultSet rs=st.executeQuery("select * from login");
            while(rs.next()==true)
            {
                Log.i("Data",rs.getString(1));

            }
            con.close();
        }
        catch(Exception e)
        {
            System.err.println("Connecting Error"+e);


        }
    }
}

在这个问题上帮我....

4

2 回答 2

1

您不应该直接从设备连接到您的 SQL Server。这是一个很大的安全风险。

最好托管一个连接到 SQL Server 的 Web 服务,并让您的 android 设备与该服务通信。

于 2012-06-28T08:11:11.730 回答
1

我遇到了同样的问题,认为构建设置没有问题,只是应用程序需要清理。

清理构建并重试..希望它应该工作。

于 2012-07-19T13:15:46.520 回答