Button button1 = findViewById(R.id.denglu);
button1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// int acc=Integer.parseInt(tex.getText().toString());
// acc=acc+1;
// tex.setText(""+acc);
new Thread(new Runnable() {
@Override
public void run() {
try {
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection cn= DriverManager.getConnection("jdbc:mysql://cdb-7iyyamp1.gz.tencentcdb.com:10024/text?useSSL=false& useUnicode=true & characterEnunicode=UTF8","","");
System.out.println("数据库连接成功");
String sql="select*from user";
Statement st=(Statement)cn.createStatement();
ResultSet rs=st.executeQuery(sql);
cn.close();
st.close();
rs.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
Toast.makeText(MainActivity.this,"数据库连接失败",Toast.LENGTH_SHORT).show();
}
}
}).start();
加急记下安卓可以用的MySQL数据库连接
猜你喜欢
转载自blog.csdn.net/qq_45541497/article/details/103720625
今日推荐
周排行