Fill in textview android studio/sql server

Asked

Viewed 212 times

1

Good guys, can’t fill a textview using a sql server database. Can anyone help me? Here’s what I have on onCreate:

connectionClass = new MainActivity();
text = (TextView) findViewById(R.id.textView4);

Connection con = connectionClass.connectionclass(connectionClass.ut, connectionClass.pw, connectionClass.db, connectionClass.server);
String query = "select text from Org";

try {

PreparedStatement ps = con.prepareStatement(query);
ResultSet rs= ps.executeQuery();


} catch (SQLException e) {
e.printStackTrace();
}

E/Surface: getSlotFromBufferLocked: unknown buffer: 0xde4f60e0
E/Surface: getSlotFromBufferLocked: unknown buffer: 0xde4f62a0
E/error here 1 :: Unknown server host name 'Host is unresolved: null'.
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.EnterpriseActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'java.sql.PreparedStatement java.sql.Connection.prepareStatement(java.lang.String)' on a null object reference
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
      at android.app.ActivityThread.-wrap11(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:5417)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
   Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.sql.PreparedStatement java.sql.Connection.prepareStatement(java.lang.String)' on a null object reference
      at EnterpriseActivity.onCreate(EnterpriseActivity.java:33)
      at android.app.Activity.performCreate(Activity.java:6237)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.app.ActivityThread.main(ActivityThread.java:5417) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  • I guess that question doesn’t need the tag sql-server because it is a matter of java.

  • It’s been a while since I’ve opened an Eclipse of Life (C# has taken over my life), but it tries to go into debug mode and see what the object con receives right after the instantiation.

1 answer

2

After Resultset rs= ps.executeQuery();

while(rs.next()){
   text.setText(rs.getString("text"));
}

Try it on and tell me if it worked

  • It didn’t work, the app stops working when I try to open Activity...

  • What message and error?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.