当前位置: 技术问答>java相关
EJB的JDBC的奇怪问题
来源: 互联网 发布时间:2015-10-30
本文导语: 这段代码在JAVABEANS中可以成功实现。 try { Class.forName("org.gjt.mm.mysql.Driver").newInstance(); Connection conn= DriverManager.getConnection("jdbc:mysql://localhost/mysql","root","dongjh"); Statement stmt=conn.creat...
这段代码在JAVABEANS中可以成功实现。
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn= DriverManager.getConnection("jdbc:mysql://localhost/mysql","root","dongjh");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//rs=stmt.executeQuery("select * from mysql.user where User='root'");
PreparedStatement upstm=conn.prepareStatement("select * from mysql.user where User=? and Password=password(?)");
upstm.setString(1,"root");
upstm.setString(2,"localhost");
rs=upstm.executeQuery();
rs.getString("User");
upstm.close();
conn.close();
}
catch(Exception e)
{
//System.out.println("驱动接口程序加载失败!!");
e.printStackTrace();
}
但是放到EJB中,却提示错误,说rs.getString("User");内容为空,这是怎么回事啊?
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn= DriverManager.getConnection("jdbc:mysql://localhost/mysql","root","dongjh");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//rs=stmt.executeQuery("select * from mysql.user where User='root'");
PreparedStatement upstm=conn.prepareStatement("select * from mysql.user where User=? and Password=password(?)");
upstm.setString(1,"root");
upstm.setString(2,"localhost");
rs=upstm.executeQuery();
rs.getString("User");
upstm.close();
conn.close();
}
catch(Exception e)
{
//System.out.println("驱动接口程序加载失败!!");
e.printStackTrace();
}
但是放到EJB中,却提示错误,说rs.getString("User");内容为空,这是怎么回事啊?
|
rs=upstm.executeQuery();
//rs.next(); -- 这一句呢?
rs.getString("User");
//rs.next(); -- 这一句呢?
rs.getString("User");
|
对啊,应该是while(rs.next){
rs.getString("user");
}
rs.getString("user");
}