提示不明确的类:java.bean.Statement 和 java.sql.Statement
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
高手指点下,搞了好久了
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
高手指点下,搞了好久了
解决方案 »
- 帮忙写一个简单的html本地文件浏览的页面(菜鸟求助)
- 谁能帮忙调一下Web service,测试通不通,好吗?非常急!
- 急救啊, 关于eWebEditor在线文本编辑器--飞鱼修改版的问题
- 关于js问题
- 请教各位高手关于隐藏和显示网页框架的问题
- 有关Win2K Pro+JBuilder5+Weblogic6+JDK1.3环境下调试jsp遇到的问题,希望大家能帮忙解答一下
- hibernate qbc hql 问题
- 获取网站地址栏地址
- mysql latin1 里 用spring mybatis取出来
- Spring MVC中restful接口的参数问题,能不在每个地方配置@RequestBody吗?
- servlet登录模块跑出IllegalStateException
- 连接数据库的问题 写在页面上可以连接 写在后台不能连接
import java.sql.*;
普通代码:可以运行,但是我感觉有缺陷,你可以先运行试试//mysqltest.java
package news;
import java.sql.*;
public class mysqltest
{
String sDBDriver = "org.gjt.mm.mysql.Driver";
private static String url="jdbc:mysql://10.164.80.52:3306/peidian?user=peidian&password=peidian-passwd&useUnicode=true&characterEncoding=gb2312";
private static Connection conn= null;
Statement stmt = null;
PreparedStatement pstmt=null;
ResultSet rs = null;//getConn
public static Connection getConn()
{
try
{
if(conn==null)
conn = DriverManager.getConnection(url);
}
catch(Exception e)
{
System.err.println("sql_data(): " + e.getMessage());
}
return conn;
}
//mysqltest
public mysqltest()
{
try
{
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("sql_data(): " + e.getMessage());
}
}
//pstmt query
public PreparedStatement execute(String sql)
{
try
{
pstmt = getConn().prepareStatement(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.executeUpdate:"+ex.getMessage());
}
return pstmt;
}
//insert
public void executeInsert(String sql)
{
try
{
stmt = getConn().createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.executeUpdate:"+ex.getMessage());
}
}
//query
public ResultSet executeQuery(String sql)
{
try
{
stmt = getConn().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.executeQuery:"+ex.getMessage());
}
return rs;
}
//update
public void executeUpdate(String sql)
{
try
{
stmt = getConn().createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.executeUpdate:"+ex.getMessage());
}
}
//delete
public void executeDelete(String sql)
{
try
{
stmt = getConn().createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
System.err.println("sql_data.executeUpdate:"+ex.getMessage());
}
}
//close
public void closeDB()
{
try
{
if(stmt != null)
{
stmt.close();
stmt = null;
}
}
catch(SQLException e)
{
e.printStackTrace();
}
try
{
if(conn != null)
{
conn.close();
conn = null;
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}}
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs为你的数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
mssqlserver.jar
msutil.jar这几个吗?有了,它提示 不明确的类: java.beans.Statement 和 java.sql.Statemet
若与java.sql.*同时引用。必然出现错误。