2

I am trying to make connection to SqlServer via Android.

I have made following code:

public class MainActivity extends Activity {


     String dbName = "AndroidDB";
     String serverip="10.0.2.2";
     String serverport="1433";
     //String url = "jdbc:sqlserver://14GRAFICALI\\MSSQLSERVER2008;databaseName="+dbName+"";
     String url ="jdbc:sqlserver://14GRAFICALIMSSQLSERVER2008;databaseName=AndroidDB;integratedSecurity=true";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        TextView tvData=(TextView)findViewById(R.id.tvSelectedData);

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
            Connection conn =DriverManager.getConnection(url);                   

            Statement statement=conn.createStatement();
            ResultSet resultSet=statement.executeQuery("select * from UserMaster");
            while(resultSet.next()){
                tvData.setText(" Data1 : "+resultSet.getString(1)+"  Data 2 : "+resultSet.getNString(2));
            }

        } catch (Exception e) {
            e.printStackTrace();
            tvData.setText(e.getMessage());
        }



    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

I have also added jars correctly.

enter image description here

Build Path Libraries:

enter image description here

Build Path Order And Export:

enter image description here

I am getting following error:

09-07 12:40:37.997: E/dalvikvm(385): Could not find class 'javax.sql.XAConnection', referenced from method com.microsoft.sqlserver.jdbc.SQLServerConnection.poolCloseEventNotify
09-07 12:40:37.997: W/dalvikvm(385): VFY: unable to resolve instanceof 444 (Ljavax/sql/XAConnection;) in Lcom/microsoft/sqlserver/jdbc/SQLServerConnection;
09-07 12:40:37.997: D/dalvikvm(385): VFY: replacing opcode 0x20 at 0x0014
09-07 12:40:37.997: D/dalvikvm(385): VFY: dead code 0x0016-001e in Lcom/microsoft/sqlserver/jdbc/SQLServerConnection;.poolCloseEventNotify ()V
09-07 12:40:58.337: W/System.err(385): com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 14GRAFICALIMSSQLSERVER2008, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
4

0 回答 0