为了账号安全,请及时绑定邮箱和手机立即绑定

Android连接MySQL问题,驱动加载成功,连接却失败

Android连接MySQL问题,驱动加载成功,连接却失败

零织 2018-12-10 10:48:49
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class MainActivity extends AppCompatActivity {     private TextView textView,textTwo;     private final static String URL = "jdbc:mysql://localhost:3306/librarydb";     static String rootName = "root";     static String PWD = "1997831";     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         textView= (TextView) findViewById(R.id.textView);         textTwo= (TextView) findViewById(R.id.textTwo);         try {             Class.forName("com.mysql.jdbc.Driver");             textView.setText("驱动加载成功");         } catch (ClassNotFoundException e) {             textView.setText("找不到驱动程序类 ,加载驱动失败!");             e.printStackTrace();         }         new Thread(new Runnable() {             @Override             public void run() {                 try {                     Connection conn= conn = (Connection) DriverManager.getConnection(URL,rootName,PWD);                     textTwo.setText("数据库连接成功!");                 } catch (SQLException e) {                     textTwo.setText("数据库连接失败!");                     e.printStackTrace();                 }             }         }).start();     } }
查看完整描述

2 回答

?
零织

TA贡献1条经验 获得超0个赞

已解决

查看完整回答
反对 回复 2018-12-10
  • 2 回答
  • 0 关注
  • 1776 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信