Java Web连接数据库进行查询时没有报错却显示不出结果,代码如下 求大神指点!!
packagedemo2;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.St...
package demo2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class selectjdbc{
Connection conn=null;
Statement stme=null;
ResultSet ress=null;
public static void main(String[] args) throws ClassNotFoundException{
new selectjdbc().searchJDBC();
}
public void searchJDBC() throws ClassNotFoundException{
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","123456");
stme=conn.createStatement();
ress=stme.executeQuery("select * from users");
while(ress.next()){
String names=ress.getString("names");
String id=ress.getString("id");
//String name=ress.getString("name");
//int jb=ress.getInt("no");
}
ress.close();
stme.close();
conn.close();
}
catch(SQLException e){
System.out.println("SQLState:"+e.getSQLState());
System.out.println("Message:"+e.getMessage());
System.out.println("Vendor:"+e.getErrorCode());
}
}
} 展开
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class selectjdbc{
Connection conn=null;
Statement stme=null;
ResultSet ress=null;
public static void main(String[] args) throws ClassNotFoundException{
new selectjdbc().searchJDBC();
}
public void searchJDBC() throws ClassNotFoundException{
try{
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","123456");
stme=conn.createStatement();
ress=stme.executeQuery("select * from users");
while(ress.next()){
String names=ress.getString("names");
String id=ress.getString("id");
//String name=ress.getString("name");
//int jb=ress.getInt("no");
}
ress.close();
stme.close();
conn.close();
}
catch(SQLException e){
System.out.println("SQLState:"+e.getSQLState());
System.out.println("Message:"+e.getMessage());
System.out.println("Vendor:"+e.getErrorCode());
}
}
} 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询