下面是javaBean 的查询数据代码
public ResultSet ExecuteQuery(String sql)
{
//sql="select * from UserInfo where id=10";
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
try
{
Context ctx = new InitialContext(ht);
DataSource ds = (DataSource)ctx.lookup("et");
conn = ds.getConnection("huaeng","admin123");
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch (NamingException ex)
{
System.out.println("NamingException_error : "+ex.getMessage());
}
catch (SQLException ex1)
{
System.out.println("SQLException_error :"+ex1.getMessage());
}
return rs;
}
在测试的jsp 中调用的代码:
<%
ResultSet rs=null;
String sql;
sql="select * from UserInfo where id=10";
rs=DataOper.ExecuteQuery(sql);
while(rs.next())
{
out.println(rs.getString("UserName"));
}
%>
public ResultSet ExecuteQuery(String sql)
{
//sql="select * from UserInfo where id=10";
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
try
{
Context ctx = new InitialContext(ht);
DataSource ds = (DataSource)ctx.lookup("et");
conn = ds.getConnection("huaeng","admin123");
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch (NamingException ex)
{
System.out.println("NamingException_error : "+ex.getMessage());
}
catch (SQLException ex1)
{
System.out.println("SQLException_error :"+ex1.getMessage());
}
return rs;
}
在测试的jsp 中调用的代码:
<%
ResultSet rs=null;
String sql;
sql="select * from UserInfo where id=10";
rs=DataOper.ExecuteQuery(sql);
while(rs.next())
{
out.println(rs.getString("UserName"));
}
%>
不好意思,我看错误的情况要么是JDBC的问题,要么是WEBLOGIC的设置问题,你留意一下吧。
at weblogic.jdbc.common.internal.RmiDataSource$1.run(RmiDataSource.java:
153)