这是我的类文件:
package WebCommon;
import java.util.*;
import java.sql.*;
import java.io.*;
public class Common
{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public Common()
{
}
public void OpenOracle()
{
try
{
java.util.Properties prop = new java.util.Properties();
InputStream is = getClass().getResourceAsStream("Oracledb.properties");
prop.load(is);
if(is!=null)
{
is.close();
}
String JDBC = prop.getProperty("dirver");
String url = prop.getProperty("url");
String user = prop.getProperty("user");
String password = prop.getProperty("password");
Class.forName(JDBC);
conn = DriverManager.getConnection(url,user,password);
}
catch(Exception err)
{
System.out.print(err.toString());
}
}
public ResultSet executeQuery(String query)throws SQLException
{
this.stmt=conn.createStatement();
this.rs=stmt.executeQuery(query);
return rs;
}
public void executeUpdate(String query)throws SQLException
{
this.stmt=conn.createStatement();
stmt.executeUpdate(query);
}
public void close()throws SQLException
{
if(conn!=null) conn.close();
if(stmt!=null) stmt.close();
if(rs!=null) rs.close();
}
public static String GetHtml(String str)
{
//str = str.replaceAll(">",">");
//str = str.replaceAll("<","<");
str = str.replaceAll("[\n]","<br>");
str = str.replaceAll(" "," ");
return str;
}
}
jsp里这样查询:
WebCommon.Common common = new WebCommon.Common();
common.OpenOracle();
String UpdateStr ="select UserName from test";
java.sql.ResultSet rs = common.executeQuery(UpdateStr);
while(rs.next())
{
out.print(rs.getString(1)+"<br>");
}
common.close();
如果把sql语句换成:select count(*) from test 就一切正常
请指教!!!
package WebCommon;
import java.util.*;
import java.sql.*;
import java.io.*;
public class Common
{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public Common()
{
}
public void OpenOracle()
{
try
{
java.util.Properties prop = new java.util.Properties();
InputStream is = getClass().getResourceAsStream("Oracledb.properties");
prop.load(is);
if(is!=null)
{
is.close();
}
String JDBC = prop.getProperty("dirver");
String url = prop.getProperty("url");
String user = prop.getProperty("user");
String password = prop.getProperty("password");
Class.forName(JDBC);
conn = DriverManager.getConnection(url,user,password);
}
catch(Exception err)
{
System.out.print(err.toString());
}
}
public ResultSet executeQuery(String query)throws SQLException
{
this.stmt=conn.createStatement();
this.rs=stmt.executeQuery(query);
return rs;
}
public void executeUpdate(String query)throws SQLException
{
this.stmt=conn.createStatement();
stmt.executeUpdate(query);
}
public void close()throws SQLException
{
if(conn!=null) conn.close();
if(stmt!=null) stmt.close();
if(rs!=null) rs.close();
}
public static String GetHtml(String str)
{
//str = str.replaceAll(">",">");
//str = str.replaceAll("<","<");
str = str.replaceAll("[\n]","<br>");
str = str.replaceAll(" "," ");
return str;
}
}
jsp里这样查询:
WebCommon.Common common = new WebCommon.Common();
common.OpenOracle();
String UpdateStr ="select UserName from test";
java.sql.ResultSet rs = common.executeQuery(UpdateStr);
while(rs.next())
{
out.print(rs.getString(1)+"<br>");
}
common.close();
如果把sql语句换成:select count(*) from test 就一切正常
请指教!!!
解决方案 »
- 如何实现两个日期时间之间大小的比较?
- struts2的action中提示信息问题!
- jsp点击多了服务器反映面慢,数据库关闭,说访问地客户端过多!
- struts 分层嵌套显示问题
- servlet跟其他jar classpath的问题
- 关于tomcat执行速度的问题
- 关于二级域名问题
- 求大家解决jasperreportreport 传参数问题
- 我到tomcat官方网下载了一个tomcat1.4,可它怎么不支持中文的?
- servlet中初始化的数据库缓冲池变量怎么找?急!
- TOMCAT5.0中如何把自己编写的SERVLET编译成CLASS文件?
- 哪里能找到Java Server Faces的资料?
String UpdateStr ="select UserName from test";
classes12.zip这个文件换个地方下一个,
最好用weblogic或其他服务器的安装目录下的那一个我为此郁闷了两个月good luck.