protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jdbc);
new
Thread(runnable).start();
}
Handler myHandler=
new
Handler(){
public
void handleMessage(Message msg) {
super.handleMessage(msg);
Bundle data=
new
Bundle();
data=msg.getData();
Log.e(
"TAG"
,
"id:"
+data.get(
"id"
).toString());
TextView tv= (TextView) findViewById(R.id.jdbc);
}
};
Runnable runnable=
new
Runnable() {
private
Connection con = null;
@Override
public
void run() {
try
{
Class.forName(
"com.mysql.jdbc.Driver"
);
con =
DriverManager.getConnection(
"jdbc:mysql://http://192.168.1.100/phpmyadmin/index.php:8086/b2b"
,
UserName,Password);
}
catch
(SQLException e) {
e.printStackTrace();
}
catch
(ClassNotFoundException e) {
e.printStackTrace();
}
try
{
testConnection(con);
}
catch
(java.sql.SQLException e) {
e.printStackTrace();
}
}
public
void testConnection(Connection con1) throws java.sql.SQLException {
try
{
String sql =
"select * from ecs_users"
;
Statement stmt = con1.createStatement();
ResultSet rs = stmt.executeQuery(sql);
Bundle bundle=
new
Bundle();
while
(rs.next()) {
bundle.clear();
bundle.putString(
"id"
,rs.getString(
"userid"
));
Message msg=
new
Message();
msg.setData(bundle);
myHandler.sendMessage(msg);
}
rs.close();
stmt.close();
}
catch
(SQLException e) {
} finally {
if
(con1 != null)
try
{
con1.close();
}
catch
(SQLException e) {}
}
}
};