package com.hl
import java.sql.DriverManager
import java.sql.ResultSet
import com.mysql.jdbc.Connection
import com.mysql.jdbc.Statement
import android.app.Activity
import android.os.Bundle
import android.view.View
import android.view.View.OnClickListener
import android.widget.Button
import android.widget.TextView
public class AndroidMsql extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
Button btn=(Button)findViewById(R.id.btn)
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sqlCon()
}
})
}
private void mSetText(String str){
TextView txt=(TextView)findViewById(R.id.txt)
txt.setText(str)
}
private void sqlCon(){
try {
Class.forName("com.mysql.jdbc.Driver")
} catch (Exception e) {
e.printStackTrace()
}
try {
String url ="jdbc:mysql://192.168.142.128:3306/mysql?user=zzfeihua&password=12345&useUnicode=true&characterEncoding=UTF-8"//链接数据库语句
Connection conn= (Connection) DriverManager.getConnection(url)//链接数据库
Statement stmt=(Statement) conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE)
String sql="select * from user"//查询user表语句
ResultSet rs=stmt.executeQuery(sql)//执行查询
StringBuilder str=new StringBuilder()
while(rs.next()){
str.append(rs.getString(1)+"\n")
}
mSetText(str.toString())
rs.close()
stmt.close()
conn.close()
} catch (Exception e) {
e.printStackTrace()
}
}
}
不过eclipse老是提示:
warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)
appinventor可以直接访问mysql数据库。根据查阅相关公开信息显示:AppInventor用于开发Android系统的应用,内嵌了若干传感器组件,可以直接调用设备的功能,比如位置传感器、加速度传感器、方向传感器、手机的拨打电话及收发短信功能。由于采用了图形化的块语言,使开发者得以更多关注自己的想法或创意,而使初学者免除了一些低级错误给开发带来的困扰,因此非常适合有想法,但苦于编程门槛偏高的初学者。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)