在JSP里我已经倒入java.sql.*,但为什么总是提示Statement stmt错误?

oldchief 2002-04-23 02:57:25
Connection con = null;//连接对象
Statement stmt;
ResultSet rs = null;
在JSP里我已经倒入java.sql.*,但为什么总是提示Statement stmt错误?而Connection,ResultSet却没问题?
...全文
31 点赞 收藏 5
写回复
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
oldchief 2002-04-23
tomcat
以前用jdk1.3的时候没有问题,但现在jdk1.4出现这个问题,程序是以前开发好的,并且在JDK1。3下没出现问题,但现在一看到Statement就提示错误!
回复
whyyy78 2002-04-23
用的是什么服务器运行jsp?
先装jdk了吗?
回复
xnfeng 2002-04-23
最后的input和output函数是转换中文的 good luck

package org.gstone.web;
import java.sql.*;


public class Mssql {

private Connection conn = null;
private Statement stmt = null;
private PreparedStatement prepstmt = null;

private String dbdriver = "com.inet.tds.TdsDriver";
private String dburl = "jdbc:inetdae:localhost?sql2000=true";

/**
* ¹¹ÔìÊý¾Ý¿âµÄÁ¬½ÓºÍ·ÃÎÊÀà
*/
public Mssql() throws Exception {
Class.forName(dbdriver);
conn = DriverManager.getConnection(dburl,"net","gstone2k");
stmt = conn.createStatement();
}
public Mssql(String sql) throws Exception {
Class.forName(dbdriver);
conn = DriverManager.getConnection(dburl,"net","gstone2k");
this.prepareStatement(sql);
}
public Mssql(int resultSetType, int resultSetConcurrency) throws Exception {
Class.forName(dbdriver);
conn = DriverManager.getConnection(dburl,"net","gstone2k");
stmt = conn.createStatement(resultSetType, resultSetConcurrency);
}
/**
* ·µ»ØÁ¬½Ó
* @return Connection Á¬½Ó
*/
public Connection getConnection() {
return conn;
}
/**
* PreparedStatement
* @return sql Ô¤ÉèSQLÓï¾ä
*/
public void prepareStatement(String sql) throws SQLException {
prepstmt = conn.prepareStatement(sql);
}
/**
* ÉèÖöÔÓ¦Öµ
* @param index ²ÎÊýË÷Òý
* @param value ¶ÔÓ¦Öµ
*/
public void setString(int index,String value) throws SQLException {
prepstmt.setString(index,value);
}
public void setInt(int index,int value) throws SQLException {
prepstmt.setInt(index,value);
}
public void setBoolean(int index,boolean value) throws SQLException {
prepstmt.setBoolean(index,value);
}
public void setDate(int index,Date value) throws SQLException {
prepstmt.setDate(index,value);
}
public void setLong(int index,long value) throws SQLException {
prepstmt.setLong(index,value);
}
public void setFloat(int index,float value) throws SQLException {
prepstmt.setFloat(index,value);
}


public void clearParameters()
throws SQLException
{
prepstmt.clearParameters();
}
/**
* ·µ»ØÔ¤Éè״̬
*/
public PreparedStatement getPreparedStatement() {
return prepstmt;
}
/**
* ·µ»Ø״̬
* @return Statement ״̬
*/
public Statement getStatement() {
return stmt;
}
/**
* Ö´ÐÐSQLÓï¾ä·µ»Ø×ֶμ¯
* @param sql SQLÓï¾ä
* @return ResultSet ×ֶμ¯
*/
public ResultSet executeQuery(String sql) throws SQLException {
if (stmt != null) {
return stmt.executeQuery(sql);
}
else return null;
}
public ResultSet executeQuery() throws SQLException {
if (prepstmt != null) {
return prepstmt.executeQuery();
}
else return null;
}
/**
* Ö´ÐÐSQLÓï¾äɾ³ý×ֶμ¯
* @param sql SQLÓï¾ä
* @return ResultSet ×ֶμ¯
*/
public void execute(String sql) throws SQLException {
if (stmt != null)
stmt.execute(sql);
}
/**
* Ö´ÐÐSQLÓï¾ä
* @param sql SQLÓï¾ä
*/
public void executeUpdate(String sql) throws SQLException {
if (stmt != null)
stmt.executeUpdate(sql);
}
public void executeUpdate() throws SQLException {
if (prepstmt != null)
prepstmt.executeUpdate();
}
/**
* ¹Ø±ÕÁ¬½Ó
*/
public void close() throws Exception {
if (stmt != null) {
stmt.close();
stmt = null;
}
if (prepstmt != null) {
prepstmt.close();
prepstmt = null;
}
conn.close();
conn = null;
}
public static String inputChinese(String s){
String temp=null;
byte db[];
try{
db=s.getBytes();
temp=new String(db,"iso-8859-1");
}catch(Exception e){
System.out.println(e);
}
return temp;
}
public static String outputChinese(String s){
String temp=null;
byte db[];
try{
db = s.getBytes("iso-8859-1");
temp = new String(db);
}catch(Exception e){
System.out.println(e);
}
return temp;
}
public static String Len(String s){
if (s==null)
{
return "";
}
String temp=null;
int i = s.length();
if (i>=16)
{
temp = s.substring(0,13) + "...";
}else{
temp = s;
}
return temp;
}

}
回复
waterdragonfly 2002-04-23
把程序贴出来看看
回复
remote_roamer 2002-04-23
Statement stmt=null;
Statement stmt是什么意思?

回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告