java mysql 问题 rs = stmt.executeQuery(sql); 这一句不能执行,怎么改啊
publicvoidshowpaper(){try{Statementstmt=null;ResultSetrs=null;Stringsql;sql="selectfi...
public void showpaper()
{
try{
Statement stmt=null;
ResultSet rs=null;
String sql;
sql="select first from timu";
System.out.print("1");
rs = stmt.executeQuery(sql);
System.out.print("2");
//text_paper.setText("sssss");
while(rs.next())
{
String sno = rs.getString("first");
text_paper.setText("sno");
}
// con.select(sql,tmp_q);
}
catch(Exception e)
{
System.out.print("3");
}
}
//ConnectDB.java
public class ConnectDB
{
private Connection connection;
Statement stat = null;
PreparedStatement pstat = null;
ResultSet rs = null;
public Connection getCon(){
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
// String url = "jdbc:mysql://localhost:8080/test1?user=root&password=admin&useUnicode=true&characterEncoding=gb2312";
// con = DriverManager.getConnection(url);
String connName = "jdbc:mysql://127.0.0.1/test";
connection = DriverManager.getConnection(connName,"root","admin");
}catch(Exception ex){
ex.printStackTrace();
}
return connection;
}
public ResultSet query(String sql){
try{
connection = getCon();
stat = connection.createStatement();
rs = stat.executeQuery(sql);
}catch(Exception ex){
ex.printStackTrace();
}
return rs;
}
} 展开
{
try{
Statement stmt=null;
ResultSet rs=null;
String sql;
sql="select first from timu";
System.out.print("1");
rs = stmt.executeQuery(sql);
System.out.print("2");
//text_paper.setText("sssss");
while(rs.next())
{
String sno = rs.getString("first");
text_paper.setText("sno");
}
// con.select(sql,tmp_q);
}
catch(Exception e)
{
System.out.print("3");
}
}
//ConnectDB.java
public class ConnectDB
{
private Connection connection;
Statement stat = null;
PreparedStatement pstat = null;
ResultSet rs = null;
public Connection getCon(){
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
// String url = "jdbc:mysql://localhost:8080/test1?user=root&password=admin&useUnicode=true&characterEncoding=gb2312";
// con = DriverManager.getConnection(url);
String connName = "jdbc:mysql://127.0.0.1/test";
connection = DriverManager.getConnection(connName,"root","admin");
}catch(Exception ex){
ex.printStackTrace();
}
return connection;
}
public ResultSet query(String sql){
try{
connection = getCon();
stat = connection.createStatement();
rs = stat.executeQuery(sql);
}catch(Exception ex){
ex.printStackTrace();
}
return rs;
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询