J**aBean连接**库问题!

时间:2013.07.17 发布人:usking

J**aBean连接**库问题!

已解决问题

谷歌usking用户在2013.07.17提交了关于“新天籁J**aBean连接**库问题!”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-10-30T13:17:34。刚接触JSP,写了个初级J**aBean连接**库!可是我在页面中调用总是出错!帮忙看一下啊!
下面是J**aBean代码.
packageorg.util;
importj**a.sql.*;
importj**ax.sql.*;

publicclassDataBase{
Stringdriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
Stringurl="jdbc:microsoft:sqlserver://localhost:1350;DataBaseName=lianxi";
Stringuser="sa";
Stringpassword="";

publicConnectiongetConn(){
Connectionconn=**ll;
try{
Class.forName("driver");
conn=DriverManager.getConnection("url,user,password");
}catch(Exceptione){}
returnconn;
}
publicStatementgetStatement(Connectionconn){
Statementstmt=**ll;
try{
if(conn!=**ll){
stmt=conn.createStatement();
}
}catch(Exceptione){}
returnstmt;
}
publicResultSetgetResultSet(Statementstmt,Stringsql){
ResultSetrs=**ll;
try{
if(stmt!=**ll){
rs=stmt.executeQuery(sql);
}
}catch(Exceptione){}
returnrs;
}
publicvoidcloseRs(ResultSetrs){
try{
if(rs!=**ll){
rs.close();
rs=**ll;
}
}catch(Exceptione){}
}
publicvoidcloseStmt(Statementstmt){
try{
if(stmt!=**ll){
stmt.close();
stmt=**ll;
}
}catch(Exceptione){}
}

publicvoidcloseConn(Connectionconn){
try{
if(conn!=**ll){
conn.close();
conn=**ll;
}
}catch(Exceptione){}
}
}
-------------------------------------------------------------
然后我想在一个.JSP文件里实现一个最简单的查询功能,就是假如从admin这张表中查询username和password,然后打印输出,该怎么写啊!我写了几次都出错了,大家帮帮忙,这个问题对于专业人员肯定很简单,可对于初学者真的是头都大了还出错啊!希望大家能够帮助她。

详细问题描述及疑问:刚接触JSP,写了个初级J**aBean连接**库!可是我在页面中调用总是出错!帮忙看一下啊!
下面是J**aBean代码.
packageorg.util;
importj**a.sql.*;
importj**ax.sql.*;

publicclassDataBase{
Stringdriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
Stringurl="jdbc:microsoft:sqlserver://localhost:1350;DataBaseName=lianxi";
Stringuser="sa";
Stringpassword="";

publicConnectiongetConn(){
Connectionconn=**ll;
try{
Class.forName("driver");
conn=DriverManager.getConnection("url,user,password");
}catch(Exceptione){}
returnconn;
}
publicStatementgetStatement(Connectionconn){
Statementstmt=**ll;
try{
if(conn!=**ll){
stmt=conn.createStatement();
}
}catch(Exceptione){}
returnstmt;
}
publicResultSetgetResultSet(Statementstmt,Stringsql){
ResultSetrs=**ll;
try{
if(stmt!=**ll){
rs=stmt.executeQuery(sql);
}
}catch(Exceptione){}
returnrs;
}
publicvoidcloseRs(ResultSetrs){
try{
if(rs!=**ll){
rs.close();
rs=**ll;
}
}catch(Exceptione){}
}
publicvoidcloseStmt(Statementstmt){
try{
if(stmt!=**ll){
stmt.close();
stmt=**ll;
}
}catch(Exceptione){}
}

publicvoidcloseConn(Connectionconn){
try{
if(conn!=**ll){
conn.close();
conn=**ll;
}
}catch(Exceptione){}
}
}
-------------------------------------------------------------
然后我想在一个.JSP文件里实现一个最简单的查询功能,就是假如从admin这张表中查询username和password,然后打印输出,该怎么写啊!我写了几次都出错了,大家帮帮忙,这个问题对于专业人员肯定很简单,可对于初学者真的是头都大了还出错啊!期待您的答案,滴水之恩,来日我当涌泉相报 !

希望以下的回答,能够帮助你。

第1个回答

用户名:cc1357531sdo  

Stringsql="select*fromadmin";
stmt=con雷留仅n.createStatement();
rs=stmt.executeQuery(sql);
//你可以获取返回的rs对象然后:
while(rs.next()){
intname=rs.getString("username");
intpass=rs。getString("password");
System.out.println(name+""+pass);
金态孩边选直}