Sebastian huth
Lurker
Hello dear helpers,
I'm new to app development and with the help of a youtube tutorial I started an app that should connect to an SQL server and query data, but now I get an error that I can't sort and hope for help from you.
Code MainActivity.java:
Code ConnectionHelper.java:
error massage:
pls help me
I'm new to app development and with the help of a youtube tutorial I started an app that should connect to an SQL server and query data, but now I get an error that I can't sort and hope for help from you.
Code MainActivity.java:
Java:
package com.huth.system;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class MainActivity extends AppCompatActivity {
Connection connect;
String ConnectionResult = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void GetTextFromSQL(View v)
{
TextView tx1 = (TextView) findViewById(R.id.textView);
TextView tx2 = (TextView) findViewById(R.id.textView2);
try {
ConnectionHelper connectionHelper = new ConnectionHelper();
connect = connectionHelper.connectionclass();
if(connect!=null)
{
String query = "SELECT * FROM `app`.`app_user` where id='1';";
Statement st = connect.createStatement();
ResultSet rs = st.executeQuery(query);
while (rs.next()){
tx1.setText(rs.getString( 1));
tx2.setText(rs.getString( 2));
}
}
else
{
ConnectionResult = "Check Connection";
}
}
catch (Exception ex){
Log.e("error2", ex.getMessage());
}
}
}
Java:
package com.huth.system;
import android.annotation.SuppressLint;
import android.os.StrictMode;
import android.util.Log;
import java.sql.Connection;
import java.sql.DriverManager;
public class ConnectionHelper {
Connection con;
String uname, pass, ip, port,database;
@SuppressLint("NewApi")
public Connection connectionclass(){
ip= "*******************";
port = "*****************";
uname = "*************";
pass = "****************";
database = "************";
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection connection = null;
String ConnectionURL = null;
try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
ConnectionURL = "jdbc:jtds:sqlserver://"+ ip + ":"+ port+";"+ "databasename="+ database+";user="+uname+";password="+pass+";";
connection = DriverManager.getConnection(ConnectionURL);
}
catch (Exception ex){
Log.e("error", ex.getMessage());
}
return connection;
}
}
E/error: I/O Error: Unknown packet type 0x63
pls help me