WebRoot/index.jsp(4,0) The value for the useBean class attribute xwfb.connectDB is invalid.

来源:百度知道 编辑:UC知道 时间:2024/05/26 15:19:42
---java code----

package xwfb;
import java.sql.*;
public class connectDB
{
String DBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String DBUrl = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=XWFB ";
String DBUser = "sa";
String DBPsw = "sa";
String test;
Connection conn = null;
PreparedStatement stmt = null;
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}

public connectDB()
{
try
{
Class.forName(DBDriver);
conn = DriverManager.getConnection(DBUrl,DBUser,DBPsw);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public ResultSet executeQuery(String sql) throws Exception
{
try
{
this.stmt = null;
this.stmt = conn.prepareStatement(sql);
return this.

public ResultSet executeQuery(String sql) throws Exception
{
try
{
this.stmt = null;
this.stmt = conn.prepareStatement(sql);
return this.stmt.executeQuery();
}
}
中return this.stmt.executeQuery()括号中应该加上sql
即return this.stmt.executeQuery(sql);
通过形参sql才能执行jsp页面上的查询语句。
希望能够帮到你。

public ResultSet executeQuery(String sql) throws Exception
{
try
{
this.stmt = null;
this.stmt = conn.prepareStatement(sql);
return this.stmt.executeQuery();
}
}
中return this.stmt.executeQuery()括号中应该加上sql
即return this.stmt.executeQuery(sql);
通过形参sql才能执行jsp页面上的查询语句。
希望能够帮到你。

I don't know