我从书中找的代码
public static Connection getConnection()
{
Connection con=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8","root","sa");
}
catch(Exception e)
{
e.printStackTrace();
}
return con;
}得到密码是调用
public static String selectPwd(String S_Num)
{
String result=null;
try
{
Connection con=getConnection();
Statement st=con.createStatement();
String sql="select S_Pwd from student where S_Num='"+S_Num+"'";
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;
}
但为什么连访问数据库都没法访问呢
public static Connection getConnection()
{
Connection con=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8","root","sa");
}
catch(Exception e)
{
e.printStackTrace();
}
return con;
}得到密码是调用
public static String selectPwd(String S_Num)
{
String result=null;
try
{
Connection con=getConnection();
Statement st=con.createStatement();
String sql="select S_Pwd from student where S_Num='"+S_Num+"'";
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;
}
但为什么连访问数据库都没法访问呢
http://www.eoeandroid.com/thread-75216-1-1.html