当前位置: 技术问答>java相关
最近在升级JDBC为2.0时遇到一问题,请高手指点一二
来源: 互联网 发布时间:2015-08-20
本文导语: 出错的代码如下: import java.util.*; import java.sql.*; public class dbconnect2 { Connection connection = null; public dbconnect2() { try { String driverName = "com.sybase.jdbc2.jdbc.SybDriver"; Driver driver = (...
出错的代码如下:
import java.util.*;
import java.sql.*;
public class dbconnect2 {
Connection connection = null;
public dbconnect2()
{
try {
String driverName = "com.sybase.jdbc2.jdbc.SybDriver";
Driver driver = (Driver)Class.forName(driverName).newInstance();
Properties p = new Properties();
p.put("user","aaa");
p.put("password","courtaaa");
String dbURL = "jdbc:sybase:Tds:10.44.16.8:4100/courtaaa";
connection = driver.connect(dbURL,p);
ResultSet rs = null;
Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sqlStr="select * from w_laxx";
rs = stmt.executeQuery(sqlStr);
}
catch (Exception e) {System.out.println("运行出错");
} }
编译时提示出错如下:
dbconnect2.java:19: No variable TYPE_SCROLL_INSENSITIVE defined in interface java.sql.ResultSet.
Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
^
dbconnect2.java:19: No variable CONCUR_READ_ONLY defined in interface java.sql.ResultSet.
Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
^
但将代码改一下直接放在JSP页面里运就不会出错,JSP中代码如下:
望高手指点一下。
import java.util.*;
import java.sql.*;
public class dbconnect2 {
Connection connection = null;
public dbconnect2()
{
try {
String driverName = "com.sybase.jdbc2.jdbc.SybDriver";
Driver driver = (Driver)Class.forName(driverName).newInstance();
Properties p = new Properties();
p.put("user","aaa");
p.put("password","courtaaa");
String dbURL = "jdbc:sybase:Tds:10.44.16.8:4100/courtaaa";
connection = driver.connect(dbURL,p);
ResultSet rs = null;
Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sqlStr="select * from w_laxx";
rs = stmt.executeQuery(sqlStr);
}
catch (Exception e) {System.out.println("运行出错");
} }
编译时提示出错如下:
dbconnect2.java:19: No variable TYPE_SCROLL_INSENSITIVE defined in interface java.sql.ResultSet.
Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
^
dbconnect2.java:19: No variable CONCUR_READ_ONLY defined in interface java.sql.ResultSet.
Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
^
但将代码改一下直接放在JSP页面里运就不会出错,JSP中代码如下:
望高手指点一下。
|
不用升级jdk,我的环境和你一样...
|
你没有完全卸载以前的JDK,完全卸在以前的JDK,把ClassPath环境变量清空,然后重新安装新的JDK。
|
可能是编译环境与JSP运行环境的JDK版本不一样