1

まず、問題を一生懸命探しているのに何も見つかりませんでした... sql serverandroidアプリケーションでエクスプレスインスタンスに接続できませんがjdbc:jtds:sqlserver、のドライバーに接続しようとしていsourceforgeます。manifestこの行をファイルに追加することを忘れないでください:

<uses-permission android:name="android.permission.INTERNET" />

そして、エラーメッセージはから情報を取得できませんsql server :HostName

ここに私のソースコードはおそらく何かが間違っています:

public class MainActivitySF extends Activity {
    private Connection connection;
    private Statement statement;
    private ResultSet resultat;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public void OnClick(View v) {
        TextView tv = (TextView) findViewById(R.id.textView1);
        EditText ehost = (EditText) findViewById(R.id.ehost);
        EditText eport = (EditText) findViewById(R.id.eport);
        EditText ebase = (EditText) findViewById(R.id.ebase);
        EditText euser = (EditText) findViewById(R.id.euser);
        EditText epasswd = (EditText) findViewById(R.id.epasswd);
        switch (v.getId()) {
        case  R.id.Connection:
            try {
                Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
            } catch (InstantiationException e){
                Toast.makeText(this, "Instantiation failled",
                        Toast.LENGTH_LONG).show();
                return;
            } catch (ClassNotFoundException e1) {
                Toast.makeText(this, "Instantiation failled",
                        Toast.LENGTH_LONG).show();
                return;
            } catch(IllegalAccessException e2){
                Toast.makeText(this, "Instantiation failled",
                        Toast.LENGTH_LONG).show();
                return;
            }
            try {
                String connString = "jdbc:jtds:sqlserver://"+ehost.getText().toString()+"" +
                                    ":"+eport.getText().toString()+"/"+ebase.getText().toString()+"" +
                                    ";encrypt=false;user="+euser.getText().toString()+";" +
                                    "password="+epasswd.getText().toString()+";instance=SQLEXPRESS;";
                String username = euser.getText().toString();
                String password = epasswd.getText().toString();
                connection = DriverManager.getConnection(connString,username,password);


            } catch (SQLException e) {
                connection = null;
                Toast.makeText(this, "connection failled",
                        Toast.LENGTH_LONG).show();
                tv.setText(e.getLocalizedMessage());
                return;
            }
            tv.setText("connection OK !!");
            break;

        case  R.id.statement:
            try {
                statement = connection.createStatement();
            } catch (SQLException e) {
                statement=null;
                Toast.makeText(this, "statement failled",
                        Toast.LENGTH_LONG).show();
                return;
            }
            tv.setText("statement OK !!");
            break;

        case  R.id.req:
            try {
                resultat = statement.executeQuery(
                        "SELECT * FROM produits");
                tv.setText(resultat.getString("LIB_PRODUIT")+ " OK !!");
            } catch (SQLException e) {
                Toast.makeText(this, "req failled",
                        Toast.LENGTH_LONG).show();
                return;
            }
            break;
        default:
            break;
        }
    }
}
4

0 に答える 0