当前位置: 技术问答>java相关
初级问题,编译该类时出错,为什么?(内有错误提示源码)
来源: 互联网 发布时间:2015-09-02
本文导语: 错误信息: D:wwwrootWEB-INFclasseswaterjava>javac waterquery.java waterquery.java:53:cannot resolve symbol symbol:constructor String location:class java.lang.Strintg sRet = new String(rs.getString(aCol)),"GBK"); ...
错误信息:
D:wwwrootWEB-INFclasseswaterjava>javac waterquery.java
waterquery.java:53:cannot resolve symbol
symbol:constructor String
location:class java.lang.Strintg
sRet = new String(rs.getString(aCol)),"GBK");
^
Note:waterquery.java uses or overrides adeprecated API.
Note:Recompile with -deprecation for details.
1 error
class代码:
package waterjava;
import java.sql.*;
import java.io.*;
import java.lang.*;
import com.sybase.jdbcx.*;
import com.sybase.jdbcx.SybDriver;
public class waterquery{
// String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sDBDriver = "com.sybase.jdbc2.jdbc.SybDriver";
Connection conn = null;
ResultSet rs;
Statement stmt;
public waterquery() {
try {
String s=new String();
String sIdx1=new String();
String sUserId=new String(),sPWD=new String();
int intIdx1, intIdx2;
String strFile = "\wwwroot\Web-inf\classes\idpwd.conf";
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(strFile)));
while((s = in.readLine())!= null){
s = s.trim();
intIdx1 = s.indexOf(":");
sIdx1 = s.substring(0,intIdx1);
if(sIdx1.equals("userid")){
sUserId=s.substring(intIdx1+1);
}
if(sIdx1.equals("password")){
sPWD=s.substring(intIdx1+1);
}
}
in.close();
Class.forName(sDBDriver);
// conn = DriverManager.getConnection("jdbc:odbc:sybase11",sUserId,sPWD);
conn = DriverManager.getConnection("jdbc:sybase:Tds:10.1.22.104:5000/rtwrdb",sUserId,sPWD);
stmt = conn.createStatement();
}
catch(Exception e) {
System.err.println("waterquery(): " + e.getMessage());
}
}
public String getString(int aCol)
{
String sRet="";
try{
// sRet = new String(rs.getBtyes(aCol),"GBK");
sRet = new String(rs.getString(aCol),"GBK");
}catch(Exception e){System.out.println(sRet+"--"+e);}
return sRet;
}
public ResultSet CreateQuery(String sql){
rs = null;
try {
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("waterquery.executeQuery: " + ex.getMessage());
}
return rs;
}
public int CreateUpdate(String sql){
int i_return = 0;
try {
i_return = stmt.executeUpdate(sql);
stmt.executeUpdate("commit");
System.out.println("commit OK");
}
catch(SQLException ex) {
System.out.println("waterquery.executeQuery: " + ex.getMessage());
try{
stmt.executeUpdate("rollback");
}catch(SQLException exem){
System.out.println("rollback Fail");
}
i_return=-1;
}
return i_return;
}
}
D:wwwrootWEB-INFclasseswaterjava>javac waterquery.java
waterquery.java:53:cannot resolve symbol
symbol:constructor String
location:class java.lang.Strintg
sRet = new String(rs.getString(aCol)),"GBK");
^
Note:waterquery.java uses or overrides adeprecated API.
Note:Recompile with -deprecation for details.
1 error
class代码:
package waterjava;
import java.sql.*;
import java.io.*;
import java.lang.*;
import com.sybase.jdbcx.*;
import com.sybase.jdbcx.SybDriver;
public class waterquery{
// String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sDBDriver = "com.sybase.jdbc2.jdbc.SybDriver";
Connection conn = null;
ResultSet rs;
Statement stmt;
public waterquery() {
try {
String s=new String();
String sIdx1=new String();
String sUserId=new String(),sPWD=new String();
int intIdx1, intIdx2;
String strFile = "\wwwroot\Web-inf\classes\idpwd.conf";
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(strFile)));
while((s = in.readLine())!= null){
s = s.trim();
intIdx1 = s.indexOf(":");
sIdx1 = s.substring(0,intIdx1);
if(sIdx1.equals("userid")){
sUserId=s.substring(intIdx1+1);
}
if(sIdx1.equals("password")){
sPWD=s.substring(intIdx1+1);
}
}
in.close();
Class.forName(sDBDriver);
// conn = DriverManager.getConnection("jdbc:odbc:sybase11",sUserId,sPWD);
conn = DriverManager.getConnection("jdbc:sybase:Tds:10.1.22.104:5000/rtwrdb",sUserId,sPWD);
stmt = conn.createStatement();
}
catch(Exception e) {
System.err.println("waterquery(): " + e.getMessage());
}
}
public String getString(int aCol)
{
String sRet="";
try{
// sRet = new String(rs.getBtyes(aCol),"GBK");
sRet = new String(rs.getString(aCol),"GBK");
}catch(Exception e){System.out.println(sRet+"--"+e);}
return sRet;
}
public ResultSet CreateQuery(String sql){
rs = null;
try {
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("waterquery.executeQuery: " + ex.getMessage());
}
return rs;
}
public int CreateUpdate(String sql){
int i_return = 0;
try {
i_return = stmt.executeUpdate(sql);
stmt.executeUpdate("commit");
System.out.println("commit OK");
}
catch(SQLException ex) {
System.out.println("waterquery.executeQuery: " + ex.getMessage());
try{
stmt.executeUpdate("rollback");
}catch(SQLException exem){
System.out.println("rollback Fail");
}
i_return=-1;
}
return i_return;
}
}
|
sRet = new String(rs.getString(aCol)),"GBK");
^
不能创建一个String用new String(String ,String),创建String只有以下方法:
String()
String(String value)
String(char value[])
String(char value[],int offset,int count)
String(byte ascii[],int hibyte,int offset,int count)
String(byte ascii[],int hibyte)
String(StringBuffer buffer)
^
不能创建一个String用new String(String ,String),创建String只有以下方法:
String()
String(String value)
String(char value[])
String(char value[],int offset,int count)
String(byte ascii[],int hibyte,int offset,int count)
String(byte ascii[],int hibyte)
String(StringBuffer buffer)
|
楼上正解!不过楼上的,你也太殷勤了吧,这样楼主自己连思考都不要思考了,你这是害他!
|
构造函数为:
String(byte[] bytes, String charsetName)
第一个为数组,不是字符串。
String(byte[] bytes, String charsetName)
第一个为数组,不是字符串。
|
给你一个建议,在声明字符串的时候,很多时候都没必要用上太多的new,这会消耗太多的系统资源。