Hi guys i have tried some codes but none work i was hoping if someone could help me. Bellow i will put my code
AndroidManisfest:
<?xml version="1.0" encoding="utf-8"?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.andre.marques.moldartsqlserver">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".InicioActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".OrdemFabricoActivity"></activity>
</application>
</manifest>
activity_ordemfabrico.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/EnterPays_atomPaysList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/ofselect"
android:layout_below="@+id/layout_inf" >
</ListView>
</LinearLayout>
ofselect.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:listPreferredItemHeightSmall"
android:orientation="horizontal"
android:showDividers="middle"
android:divider="?android:dividerVertical"
android:dividerPadding="8dp"
android:gravity="center">
<TextView android:id="@+id/Codart"
style="?android:textAppearanceMedium"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:paddingLeft="?android:listPreferredItemPaddingLeft" />
<TextView android:id="@+id/quantidade"
style="?android:textAppearanceMedium"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
ConnectionClass:
public class ConnectionClass {
String ip;
String classs;
String db;
String un;
String password;
public ConnectionClass() {
classs = "net.sourceforge.jtds.jdbc.Driver";
db = "DatabaseName";
un = "user";
password = "XXXXXXXX";
ip = "192.xxx.x.xxx";
}
public ConnectionClass(String Ip, String Classs, String Db, String Un, String Password) {
ip = Ip;
classs = Classs;
db = Db;
un = Un;
password = Password;
}
public String getip() {
return ip;
}
public String getclasss() {
return classs;
}
public String getdb() {
return db;
}
public String getun() {
return un;
}
public String getpassword() {
return password;
}
public void setip(String Ip) {
ip = Ip;
}
public void setdb(String Db) {
db = Db;
}
public void setclasss(String Classs) {
classs = Classs;
}
public void setun(String Un) {
un = Un;
}
public void setpassword(String Password) {
password = Password;
}
}
OrdemFabricoActivity:
public class OrdemFabricoActivity extends Activity {
ConnectionClass connectionclass;
ListView lst;
SimpleAdapter ADAhere;
String usernameS;
String datets;
String call, db, un, passwords;
Connection connect;
ResultSet rs;
@SuppressLint("NewApi")
private Connection CONN(String _user, String _pass, String _DB, String _server) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection conn = null;
String ConnURL = null;
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
ConnURL = "jdbc:jtds:sqlserver://" + _server + ";" + "databaseName=" + _DB + ";user=" + _user + ";password=" + _pass + ";";
conn = DriverManager.getConnection(ConnURL);
} catch (SQLException se) {
Log.e("ERRO", se.getMessage());
} catch (ClassNotFoundException e) {
Log.e("ERRO", e.getMessage());
} catch (Exception e) {
Log.e("ERRO", e.getMessage());
}
return conn;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ordemfabrico);
lst = (ListView) findViewById(R.id.EnterPays_atomPaysList);
/************* CONNECTION DATABASE VARIABLES ***************/
connectionclass = new ConnectionClass();
call = connectionclass.getip();
un = connectionclass.getun();
passwords = connectionclass.getpassword();
db = connectionclass.getdb();
connect = CONN(un, passwords, db, call);
String querycmd = "select NUMOF, COD_ART, DESC_ART, OBSERVACOES, QUANT from tabof where tabof.ID_TO <> 5";
try {
Statement statement = connect.createStatement();
rs = statement.executeQuery(querycmd);
List<Map<String, String>> data = null;
data = new ArrayList<Map<String, String>>();
while (rs.next()) {
Map<String, String> datanum = new HashMap<String, String>();
datanum.put("A", rs.getString("COD_ART"));
//datanum.put("B", rs.getString("QUANT"));
data.add(datanum);
}
String[] fromwhere = { "A" };
int[] viewswhere = { R.id.Codart };
ADAhere = new SimpleAdapter(OrdemFabricoActivity.this, data, R.layout.ofselect, fromwhere, viewswhere);
lst.setAdapter(ADAhere);
} catch (SQLException e) {
Toast.makeText(OrdemFabricoActivity.this, e.getMessage().toString(), Toast.LENGTH_LONG).show();
}
}
}
This is my code the result that i get with this code it is when i go to this activity my phone screen is black and nothing happen. I wanted to put in the labels Codart and quant the value of some camps of the database if someone know how to do this please help me.