import java.io.*;
import java.util.*;
import java.sql.*;
public class bean
{
Connection Con=null;
public bean(){BuildConnection();}
public void BuildConnection(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Con = DriverManager.getConnection("jdbc:odbc:xxy","sa","");
}catch (Exception e) {
System.out.println(e.getMessage());}
}public Connection getConnection()
{
if(Con==null)
BuildConnection();
return this.Con;
}
public void close()
{try{
Con.close();
Con=null;
}
catch(SQLException e){
System.out.println(e.getMessage());
}
}
try{
String pass;Statement stm=Con.createStatement();
public String checkd(String username,String password)
{
String sql="select password from dl where name='"+ username + "'";
ResultSet rs=stm.executeQuery(sql);
if(rs==null)
return("请输入用户名!");
while(rs.next()){
pass = rs.getString(2);
}
if(pass.equals(password))
return("登录成功!");
else
return("密码错误!");
}
}
catch(SQLException e){
System.out.println(e.getMessage());
}}哪位高手帮忙指点下错误````小弟感激不尽
import java.util.*;
import java.sql.*;
public class bean
{
Connection Con=null;
public bean(){BuildConnection();}
public void BuildConnection(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Con = DriverManager.getConnection("jdbc:odbc:xxy","sa","");
}catch (Exception e) {
System.out.println(e.getMessage());}
}public Connection getConnection()
{
if(Con==null)
BuildConnection();
return this.Con;
}
public void close()
{try{
Con.close();
Con=null;
}
catch(SQLException e){
System.out.println(e.getMessage());
}
}
try{
String pass;Statement stm=Con.createStatement();
public String checkd(String username,String password)
{
String sql="select password from dl where name='"+ username + "'";
ResultSet rs=stm.executeQuery(sql);
if(rs==null)
return("请输入用户名!");
while(rs.next()){
pass = rs.getString(2);
}
if(pass.equals(password))
return("登录成功!");
else
return("密码错误!");
}
}
catch(SQLException e){
System.out.println(e.getMessage());
}}哪位高手帮忙指点下错误````小弟感激不尽
搞的我莫名其妙
如果是这个异常,就是你的classpath中没有这个驱动
Connection Con = null; public bean() {
BuildConnection();
} public void BuildConnection() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Con = DriverManager.getConnection("jdbc:odbc:xxy", "sa", ""); } catch (Exception e) {
System.out.println(e.getMessage());
}
} public Connection getConnection() {
if (Con == null)
BuildConnection();
return this.Con;
} public void close() {
try {
Con.close();
Con = null;
} catch (SQLException e) {
System.out.println(e.getMessage());
}
} public String checkd(String username, String password) {
String pass = null;
try { Statement stm = Con.createStatement(); String sql = "select password from dl where name='"
+ username + "'";
ResultSet rs = stm.executeQuery(sql);
if (rs == null)
return ("请输入用户名!");
if (rs.next()) {
pass = rs.getString(2);
} } catch (SQLException e) {
System.out.println(e.getMessage());
}
if (pass.equals(password))
return ("登录成功!");
else
return ("密码错误!"); }}
高手些帮我调试一下嘛``拜托了
while (rs.next()) → if (rs.next())
这句话怎么没有对象呀,只是一个表达式,你把你要定义的类加在前面就OK了!!!
这样试试:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
后面那个try模块有逻辑错误。自己好好分析一下。还有后面try模块里的String pass是没有初始化的变量,可能会报空指针错误。
建议改为String pass=null;
import java.util.*;
import java.sql.*;public class bean {
Connection Con = null; public bean() {
BuildConnection();
} public void BuildConnection() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Con = DriverManager.getConnection("jdbc:odbc:xxy", "sa", ""); } catch (Exception e) {
System.out.println(e.getMessage());
}
} public Connection getConnection() {
if (Con == null)
BuildConnection();
return this.Con;
} public void close() {
try {
Con.close();
Con = null;
} catch (SQLException e) {
System.out.println(e.getMessage());
}
} public String checkd(String username, String password) {
try {
String pass=null; Statement stm = Con.createStatement();
String sql = "select password from dl where name='"
+ username + "'";
ResultSet rs = stm.executeQuery(sql);
if (rs == null)
return ("请输入用户名!");
while (rs.next()) {
pass = rs.getString(2); }
if (pass.equals(password))
return ("登录成功!");
else
return ("密码错误!"); } catch (SQLException e) {
System.out.println(e.getMessage());
return "";
}
}}
Connection Con = null; public pp() {
BuildConnection();
} public void BuildConnection() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Con = DriverManager.getConnection("jdbc:odbc:wd", "system", "manager"); } catch (Exception e) {
System.out.println(e.getMessage());
}
} public Connection getConnection() {
if (Con == null)
BuildConnection();
return this.Con;
} public void close() {
try {
Con.close();
Con = null;
} catch (SQLException e) {
System.out.println(e.getMessage());
}
} public String checkd(String username, String password) {
String pass = null;
try {
Statement stm = Con.createStatement();
String sql = "select aa from wdtest where aa='" + username + "'";
ResultSet rs = stm.executeQuery(sql);
if (rs == null)
return ("Please insert user name!");
if (rs.next()) {
pass = rs.getString(1);
} } catch (SQLException e) {
System.out.println(e.getMessage());
}
if (pass.equals(password))
return ("OK!");
else
return ("password error!"); }
public static void main(String[] args){
pp z = new pp();
String info = z.checkd("test", "test");
System.out.println(info);
z.close();
}
}
String pass; Statement stm=Con.createStatement();
public String checkd(String username,String password) //try都没完,你就来个函数,肯定报非法表达式错误落!悲哀