qq_18286723
2015-02-22 17:56
采纳率: 50%
浏览 1.6k

求大神解答衣蛾android问题

本人是菜鸟,才学android没有几天,求大神解答下问题:
我写了一段android连接mysql数据库的代码,日志显示:caused by: android.os.NetworkOnMainThreadException,另外显示有两处错误(错误行代码有注释)

package com.example.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DBUtil {
public static Connection getConnection()
{
Connection con=null;
try
{

Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/phpmyadmin/sql.php?db=test&table=test_table&server=1&target=&token=8d4f159026cbb703acf36034c2082a64#PMAURL-2:db_structure.php?db=test&table=&server=1&target=&token=c5d26db979b50cc6775e3dac84699d95","root",""); //这一行有错

}
catch(Exception e)
{
e.printStackTrace();
}
return con;
}

public static String selectPwd(String ID)
{
    String result=null;
    try
    {
        Connection con=getConnection();         
        Statement st=con.createStatement(); //这一行有错  
        String sql="select password from test_table where ID='"+ID+"'";
        ResultSet rs=st.executeQuery(sql);
        if(rs.next())
        {
            result=rs.getString(1);
        }
        rs.close();
        st.close();
        con.close();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    return result;      
}

}

5条回答 默认 最新

相关推荐 更多相似问题