当前位置: 技术问答>java相关
帮忙看看哪里错了,谢谢!在线等待~~
来源: 互联网 发布时间:2015-09-07
本文导语: 我不明白为什么不能通过编译? 代码如下: package yida; import java.sql.*; import java.util.*; public class Pass{ public HashSet hsAuth=new HashSet(); private String Username=""; private String Password=""; private String g_name=null; private String Pe...
我不明白为什么不能通过编译?
代码如下:
package yida;
import java.sql.*;
import java.util.*;
public class Pass{
public HashSet hsAuth=new HashSet();
private String Username="";
private String Password="";
private String g_name=null;
private String Personnel_id=null;
public Connection conn=null;
int auth=0;
int num=0;
public void setPass(String pusername,String ppasswd,String L_session_id) throws ClassNotFoundException,SQLException{
PreparedStatement prepare;
ResultSet rs;
String SQL;
DBConnect dbc=new DBConnect();
Connection dbc=dbc.getConn();
SQL="select*from t_user where u_name=?";
prepare=conn.PrepareStatement(SQL);
prepare.setString(1,pusername);
rs=prepare.executeQuery();
if(rs.next()){
if(ppasswd.equals(rs.getString("u_password"))){
Username=pusername;
Password=ppasswd;
g_name=rs.getString("g_name");
Personnel_id=rs.getString("t_gonghao");
num=0;
auth=1;
SQL="insert into t_log(u_name,L_regtime,L_success)vaules(?,now(),1)";
prepare=conn.prepareStatement(SQL);
/**
* Short concise description.
* Additional verbose description.
* @return description.
* @see package.class
*/
prepare.setString(1,pusername);
}
else{
SQL="insert into t_log(u_name,L_regtime,L_success,L_session_id,L_errPass)values(?,now(),0,?,?)";
prepare=conn.PrepareStatement(SQL);
prepare.setString(1,pusername);
prepare.setString(2,L_session_id);
prepare.setString(3,ppasswd);
num++;
auth=2;
}
prepare.executeUpdate();
}
else{
num++;
auth=0;
}
if(auth==1){
SQL="select*from group where g_name=?";
prepare=conn.PrepareStatement(SQL);
prepare.setString(1,g_name);
rs=prepare.executeQuery();
hsAuth.clear();
for(int i=0;rs.next();i++){
hsAuth.add(rs.getString("spac"));
}
}
if(auth==3){
return;
}
rs.close();
}
public HashSet getAuth(){
return(hsAuth);
}
public int getNum(){
return(num);
}
public String getg_name(){
return(String.valueOf(g_name));
}
public int getAuth(String authname){
if(hsAuth.contains(authname))
{
return(1);
}
else
return(0);
}
public int getPass(){
return(auth);
}
public String Username(){
return(Username);
}
public String getPassword(){
return(Password);
}
public void logout(){
Username=null;
Password=null;
g_name=null;
num=0;
auth=0;
}
}
错误如下:
---------------- JDK Release Build ------------------
Compiling D:yida OA系统yida OABeansPass.java
D:yida OA系统yida OABeansPass.java:17: cannot resolve symbol
symbol : class DBConnect
location: class yida.Pass
DBConnect dbc=new DBConnect();
^
D:yida OA系统yida OABeansPass.java:17: cannot resolve symbol
symbol : class DBConnect
location: class yida.Pass
DBConnect dbc=new DBConnect();
^
D:yida OA系统yida OABeansPass.java:20: cannot resolve symbol
symbol : method PrepareStatement (java.lang.String)
location: interface java.sql.Connection
prepare=conn.PrepareStatement(SQL);
^
D:yida OA系统yida OABeansPass.java:44: cannot resolve symbol
symbol : method PrepareStatement (java.lang.String)
location: interface java.sql.Connection
prepare=conn.PrepareStatement(SQL);
^
D:yida OA系统yida OABeansPass.java:59: cannot resolve symbol
symbol : method PrepareStatement (java.lang.String)
location: interface java.sql.Connection
prepare=conn.PrepareStatement(SQL);
^
5 errors
Finished
代码如下:
package yida;
import java.sql.*;
import java.util.*;
public class Pass{
public HashSet hsAuth=new HashSet();
private String Username="";
private String Password="";
private String g_name=null;
private String Personnel_id=null;
public Connection conn=null;
int auth=0;
int num=0;
public void setPass(String pusername,String ppasswd,String L_session_id) throws ClassNotFoundException,SQLException{
PreparedStatement prepare;
ResultSet rs;
String SQL;
DBConnect dbc=new DBConnect();
Connection dbc=dbc.getConn();
SQL="select*from t_user where u_name=?";
prepare=conn.PrepareStatement(SQL);
prepare.setString(1,pusername);
rs=prepare.executeQuery();
if(rs.next()){
if(ppasswd.equals(rs.getString("u_password"))){
Username=pusername;
Password=ppasswd;
g_name=rs.getString("g_name");
Personnel_id=rs.getString("t_gonghao");
num=0;
auth=1;
SQL="insert into t_log(u_name,L_regtime,L_success)vaules(?,now(),1)";
prepare=conn.prepareStatement(SQL);
/**
* Short concise description.
* Additional verbose description.
* @return description.
* @see package.class
*/
prepare.setString(1,pusername);
}
else{
SQL="insert into t_log(u_name,L_regtime,L_success,L_session_id,L_errPass)values(?,now(),0,?,?)";
prepare=conn.PrepareStatement(SQL);
prepare.setString(1,pusername);
prepare.setString(2,L_session_id);
prepare.setString(3,ppasswd);
num++;
auth=2;
}
prepare.executeUpdate();
}
else{
num++;
auth=0;
}
if(auth==1){
SQL="select*from group where g_name=?";
prepare=conn.PrepareStatement(SQL);
prepare.setString(1,g_name);
rs=prepare.executeQuery();
hsAuth.clear();
for(int i=0;rs.next();i++){
hsAuth.add(rs.getString("spac"));
}
}
if(auth==3){
return;
}
rs.close();
}
public HashSet getAuth(){
return(hsAuth);
}
public int getNum(){
return(num);
}
public String getg_name(){
return(String.valueOf(g_name));
}
public int getAuth(String authname){
if(hsAuth.contains(authname))
{
return(1);
}
else
return(0);
}
public int getPass(){
return(auth);
}
public String Username(){
return(Username);
}
public String getPassword(){
return(Password);
}
public void logout(){
Username=null;
Password=null;
g_name=null;
num=0;
auth=0;
}
}
错误如下:
---------------- JDK Release Build ------------------
Compiling D:yida OA系统yida OABeansPass.java
D:yida OA系统yida OABeansPass.java:17: cannot resolve symbol
symbol : class DBConnect
location: class yida.Pass
DBConnect dbc=new DBConnect();
^
D:yida OA系统yida OABeansPass.java:17: cannot resolve symbol
symbol : class DBConnect
location: class yida.Pass
DBConnect dbc=new DBConnect();
^
D:yida OA系统yida OABeansPass.java:20: cannot resolve symbol
symbol : method PrepareStatement (java.lang.String)
location: interface java.sql.Connection
prepare=conn.PrepareStatement(SQL);
^
D:yida OA系统yida OABeansPass.java:44: cannot resolve symbol
symbol : method PrepareStatement (java.lang.String)
location: interface java.sql.Connection
prepare=conn.PrepareStatement(SQL);
^
D:yida OA系统yida OABeansPass.java:59: cannot resolve symbol
symbol : method PrepareStatement (java.lang.String)
location: interface java.sql.Connection
prepare=conn.PrepareStatement(SQL);
^
5 errors
Finished
|
DBConnect dbc=new DBConnect();
Connection dbc=dbc.getConn();
首先,你使用的DBConnect类java里面根本就不存在这个类阿,应该是写错类名了吧?
另外,你怎么将Connection变量也命名为dbc?看你后面的代码及错误提示,此处应该命名为conn才对阿
Connection dbc=dbc.getConn();
首先,你使用的DBConnect类java里面根本就不存在这个类阿,应该是写错类名了吧?
另外,你怎么将Connection变量也命名为dbc?看你后面的代码及错误提示,此处应该命名为conn才对阿
|
1、没有找到DBConnection这个Class,应该import这个class
2、没找到PrepareStatement这个方法,应该是prepareStatement,第一个字母小写
2、没找到PrepareStatement这个方法,应该是prepareStatement,第一个字母小写
|
你得把yida所在的路径加入到classpath中。
|
那么你的classpath设置有问题