我遇到变量和字符串之间操作数类型不兼容的错误。这是我的代码片段。错误发生@ if ( handler == "CLOSE")
最重要的是,我是否正确连接了我的数据库?应该有一个“public void closeDB”,但是包含该语句时出现错误。
private DBHandler handler;
public void openDB() throws SQLException
{
// Open the DB Connection
final String DBURL = "example";
final String DBUSER = "example";
final String DBPASS = "example";
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
Connection con = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
Statement statement = con.createStatement();
}
public void setFileName(String fileName)
{
this.fileName = fileName;
}
public void setMySQL( String mySQL )
{
this.mySQL = mySQL;
}
public ResultSet retrieveTheData( ) throws SQLException
{
if ( handler == null )
{
// Create a new connection
}
if ( handler == "CLOSE" )
{
// Open the connection
}
// Message the Data
ResultSet rs;
return rs;
}
最佳答案
使用字符串的equals(Object anObject)适合您的工作:
"CLOSE".equals(handler.toString())
关于java - 变量和字符串之间不兼容的操作数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29530445/