亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用JDBC從Android連接到MySQL

使用JDBC從Android連接到MySQL

當年話下 2019-09-03 15:59:25
我用下面的代碼連接MySQL在localhost從Android系統。它僅顯示catch部分中給出的操作。我不知道是否是連接問題。package com.test1;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class Test1Activity extends Activity {    /** Called when the activity is first created. */    String str="new";    static ResultSet rs;    static PreparedStatement st;    static Connection con;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        final   TextView tv=(TextView)findViewById(R.id.user);        try        {            Class.forName("com.mysql.jdbc.Driver");              con=DriverManager.getConnection("jdbc:mysql://10.0.2.2:8080/example","root","");            st=con.prepareStatement("select * from country where id=1");            rs=st.executeQuery();             while(rs.next())             {             str=rs.getString(2);             }            tv.setText(str);            setContentView(tv);        }        catch(Exception e)        {            tv.setText(str);        }    }}當此代碼執行時,它在avd中顯示“new”。java.lang.management.ManagementFactory.getThreadMXBean, referenced from method com.mysql.jdbc.MysqlIO.appendDeadlockStatusInformationCould not find class 'javax.naming.StringRefAddr', referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.storeToCould not find method javax.naming.Reference.get, referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.initializeFrom有誰能建議一些解決方案?并提前感謝
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 671 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號