K
kylin_2000
Unregistered / Unconfirmed
GUEST, unregistred user!
刚刚开始学习jsp,可是在连接数据库时就出问题。程序如下:
///javaBean
package voter;
import java.sql.*;
public class votertBean {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbcdbc:voter";
String user = "sa";
String pwd = "";
Connection connect = null;
ResultSet rs = null;
public votertBean(){
try{
Class.forName(sDBDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println(e.getMessage());
}
}
public ResultSet executeQuery(String sql){
rs = null;
try{
connect = DriverManager.getConnection(sConnStr, user, pwd);
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(sql);
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
return rs;
}
}
///jsp
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="voteBean" scope="session" class="voter.votertBean" />
<jsp:setProperty name="voteBean" property="*" />
<html>
...........................
use JBuider5
///javaBean
package voter;
import java.sql.*;
public class votertBean {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbcdbc:voter";
String user = "sa";
String pwd = "";
Connection connect = null;
ResultSet rs = null;
public votertBean(){
try{
Class.forName(sDBDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println(e.getMessage());
}
}
public ResultSet executeQuery(String sql){
rs = null;
try{
connect = DriverManager.getConnection(sConnStr, user, pwd);
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(sql);
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
return rs;
}
}
///jsp
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="voteBean" scope="session" class="voter.votertBean" />
<jsp:setProperty name="voteBean" property="*" />
<html>
...........................
use JBuider5