package comaccpbbstest;
import javasqlConnection;
import javasqlDriverManager;
import javasqlResultSet;
import javasqlSQLException;
import javasqlStatement;
import javautilArrayList;
import javautilList;
public class BaseDao{
public final static String DRIVER = "commicrosoftsqlserverjdbcSQLServerDriver";
public final static String URL = "jdbc:sqlserver://localhost:1433;DataBaseName = bbs";
public final static String DBNAME = "sa";
public final static String DBPASS = "sa";
public static Connection getConn() throws ClassNotFoundException, SQLException {
ClassforName(DRIVER);
Connection conn = DriverManagergetConnection(URL, DBNAME, DBPASS);
return conn;
}
public List<Integer> getList(){
List<Integer> list= new ArrayList<Integer>();
String SQL="select Id from user";
try{
Connection conn = BaseDaogetConn();
Statement stmt = conncreateStatement();
ResultSet rs = stmtexecuteQuery(SQL);
while(rsnext()){
listadd(rsgetInt("Id"));
}
}catch(Exception e){
Systemoutprintln("有异常");
}
return list;
}
public static void main(String[] args) {
BaseDao baseDao = new BaseDao();
List<Integer> list= baseDaogetList();
for(Integer i : list){
Systemoutprintln(i);
}
}
}
程序本身没有问题。但是,你先把这个SQL语句拿到数据库里面去查询一下,看看有没有查询记录呢!
String str="0";
preparedStmt =sqlConprepareStatement("select state,come,des,subject,content
from yymail where state like '"+str+"'");
即select state,come,des,subject,content from yymail where state like '0'
我估计是你SQL语句有问题。
如果SQL语句没有问题了,你再照楼上康熙的方法去解决其它相关问题。
private static Connection con = null;
private static PreparedStatement pst = null;
private static ResultSet rs = null;
public static int CheckUser(String username,String password)
{
int i = 0;
try
{
con = ConnectionDatabaseGetConnections();
pst = conprepareStatement("sql语句");
rs = pstexecuteQuery();
if(rsnext())
{
i = 10;
}
}
catch(Exception e)
{
eprintStackTrace();
}
finally
{
try
{
rsclose();
pstclose();
conclose();
}
catch(Exception ee)
{
eeprintStackTrace();
}
}
return i;
}这是一个查询执行的代码,,,你这里应该将这个sql语句传到这个方法里面,,然后执行就可以啦。
以上就是关于关于java读取sql,得到的结果list的问题。。。全部的内容,包括:关于java读取sql,得到的结果list的问题。。。、java SQL select 语句 获取不到查询结果、java 执行SQL返回结果等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)