编译.java找不到符号

Malachi 2009-05-22 10:41:35


BaseConn.java
----------------------------------------------------------------------------------------------------------------------------

package net.chat;
import java.sql.*;
import java.lang.ClassNotFoundException;
public class BaseConn{
Connection conn=null;
Statement stmt=null;
PreparedStatement ps=null;
ResultSet rs=null;
/**************************************************************************************
*BaseConn的构造函数,在这里完成数据库的初始化操作,即连接数据库操作
**************************************************************************************/
public BaseConn()throws SQLException,ClassNotFoundException{
try
{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ChatRoom;SelectMethod=Cursor";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn=DriverManager.getConnection(url,"sa","");
stmt=conn.createStatement();
}
catch(SQLException e)
{
System.out.println("Error occured when Connect DataBase:"+e);
throw e;
}
catch(ClassNotFoundException e)
{
System.out.println("Error occured when Connect DataBase:"+e);
throw e;
}
}
/*************************************************************************************
*初始化预编译的SQL语句的对象
************************************************************************************/
public PreparedStatement prepaeStatement(String sql)throws SQLException
{
try
{
ps=conn.prepareStatement(sql);
return ps;
}catch(SQLException e)
{
System.out.println("Error occured when create preparedStatement:"+e);
throw e;
}
}
/*************************************************************************************
*执行静态SQL查询语句并返回它所生成结果的对象
************************************************************************************/
public ResultSet ececuteQuery(String sql)throws SQLException
{
rs=null;
try{
rs=stmt.executeQuery(sql);
}
catch(SQLException ex){
System.out.println("Error occured when query database:"+ex);
throw ex;
}
return rs;
}
/*************************************************************************************
*执行静态SQL查询语句并返回影响数据的条数
************************************************************************************/
public int executeUpadate(String sql)throws SQLException
{
try{
conn.setAutoCommit(false);
int re=stmt.executeUpdate(sql);
conn.commit();
return re;
}
catch(SQLException e){
conn.rollback();
System.out.println("Error occured when update database:"+e);
throw e;
}
}
/*************************************************************************************
*执行预先SQL查询语句
************************************************************************************/
public ResultSet executeQuery() throws SQLException
{
try{
return ps.executeQuery();
}
catch(SQLException e){
System.out.println("Error occured when query database:"+e);
throw e;
}
}
/*************************************************************************************
*执行预编译的SQL更新语句
************************************************************************************/
public int executeUpdate() throws SQLException
{
try{
conn.setAutoCommit(false);
int r=ps.executeUpdate();
conn.commit();
return r;
}
catch(SQLException e){
conn.rollback();
System.out.println("Error occured when updata database:"+e);
throw e;
}
}
/*************************************************************************************
*数据库关闭操作
************************************************************************************/ public boolean closeDB() throws SQLException
{
try{
if(this.rs!=null)
rs.close();
if(this.stmt!=null)
this.stmt.close();
if(this.ps!=null)
this.ps.close();
if(this.conn!=null)
conn.close();
return true;
}
catch (SQLException e){
System.out.println("Error occured when close database:"+e);
throw e;
}
}
}


---------------------------------------------------------------------------------------------------------------------------
BaseConn.java编译通过



CheckLogin.java

----------------------------------------------------------------------------------------------------------------------------

package net.chat;
import java.sql.*;
import java.util.*;
import java.text.SimpleDateFormat;
import java.lang.ClassNotFoundException;
public class CheckLogin{
/*
检测用户登陆信息
用户登陆的用户名
用户登陆的密码
*/
public String checklogin(String userName,String userPassword) throws SQLException,ClassNotFoundException
{
BaseConn conn=null;
try
{
conn=new BaseConn();
//创建一个预先处理的SQL语句
String sql="select *from userInfo where nickName=?";
//创建一个预先处理的SQL对象
PreparedStatement ps=conn.preparedStatement(sql);
ps.setString(1,userName);
//从用户数据库中查询该用户名是否在数据库中
ResultSet rs=conn.executeQuery();
if(rs.next())
{
if(rs.getString("userPassword").equals(userPassword))
{
SimpleDateFormat cal=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time=cal.format(new java.util.Date());
//修改用户的最后登陆时间
sql="update userinfo set lastLoginTime?where nickName=?";
ps=conn.prepareStatement(sql);
ps.setString(1,time);
ps.setString(2,userName);
conn.executeUpdate();
return "SUCCESS_LOGIN";
}
else
return "WRONG_PASSWORD";
}
else
return "NONE_USER";
}catch(SQLException ex)
{
ex.printStackTrace();
throw ex;
}catch(ClassNotFoundException ex)
{
ex.printStackTrace();
throw ex;
}
finally
{
conn.close();//关闭数据库连接,释放JDBC资源
}
}
/*
如果是新用户,则将用户登陆用户名和密码保存到数据库中
*/
public boolean saveToDataBase(String userName,String userPassword) throws SQLException,ClassNotFoundException
{
BaseConn conn=null;
try
{
conn=new BaseConn();
SimpleDateFormat cal=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time=cal.format(new java.util.Date());
String sql="insert into userInfo(nickName,userPassword,lastLoginTime)values (?,?,?)";
PreparedStatement ps =conn.prepareStatement(sql);
ps.setString(1,userName);
ps.setString(2,userPassword);
ps.setString(3,time);
conn.executeUpdate();
return true;
}catch(SQLException ex)
{
ex.printStackTrace();
throw ex;
}finally
{
conn.close();//关闭数据库连接,释放JDBC资源
}
}
}

------------------------------------------------------------------------------------------------------------------------------

CheckLogin.java 编译的时候 出现错误

D:\ChatRoom\WEB-INF>javac CheckLogin.java
CheckLogin.java:14: 找不到符号
符号: 类 BaseConn
位置: 类 net.chat.CheckLogin
BaseConn conn=null;
^
CheckLogin.java:17: 找不到符号
符号: 类 BaseConn
位置: 类 net.chat.CheckLogin
conn=new BaseConn();
^
CheckLogin.java:63: 找不到符号
符号: 类 BaseConn
位置: 类 net.chat.CheckLogin
BaseConn conn=null;
^
CheckLogin.java:66: 找不到符号
符号: 类 BaseConn
位置: 类 net.chat.CheckLogin
conn=new BaseConn();
^
4 错误


寻求帮助
...全文
3635 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hepeng19861212 2009-05-22
  • 打赏
  • 举报
回复
更建议使用myEclipse
hepeng19861212 2009-05-22
  • 打赏
  • 举报
回复
换成eclipse来开发吧。

在CheckLogin.java 开头加上 import net.chat.*;
Malachi 2009-05-22
  • 打赏
  • 举报
回复
恩,可是我把CheckLogin.java 放到net/chat 文件夹下 还是找不到。。
myEclipse 不会用。。
qiheia 2009-05-22
  • 打赏
  • 举报
回复
路径错咯,找不到BaseConn.java
Dream_gril 2009-05-22
  • 打赏
  • 举报
回复
找不到BaseConn类。
loveunittesting 2009-05-22
  • 打赏
  • 举报
回复
可能是找不到BaseConn的类。可以设置一下classpath,把你的类根目录加入进去。
或者编译时候直接指定 如:javac classpath=%classpath;./ CheckLogin.java

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧