帮忙看个简单代码
package GetLogin;
import java.io.*;
import java.sql.*;
import java.util.*;
public class GoLogin
{
public String GoToLogin(String ID,String PASS)
{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver://10.4.234.87:1433;DatabaseName=DCMSMOD ";
String user= "sa ";
String password= "518518 ";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String SQL = " SELECT * FROM DCMSMOD..DSCMA Where MA001= ' " + ID + " ' " + " and MA003= ' " + PASS + " ' ";
ResultSet rs=stmt.executeQuery(SQL);
rs.first();
if (rs.getString( "MA001 ") == " ")
return "Login_ok ";
else
return "Login_error ";
}
}
可报错呀,麻烦大家看看!
------解决方案--------------------把错误帖出来啊,而且你那个RS没有循环,光在头上了
------解决方案--------------------动态加载类,获取数据库连接等操作很容易发生异常,系统规定必须要为这些操作捕捉异常:
修改后的代码如下:
import java.io.*;
import java.sql.*;
import java.util.*;
public class GoToLogin
{
public String GoToLogin(String ID, String PASS)
{
try
{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").
newInstance();
String url =
"jdbc:microsoft:sqlserver://10.4.234.87:1433;DatabaseName=DCMSMOD ";
String user = "sa ";
String password = "518518 ";
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String SQL = " SELECT * FROM DCMSMOD..DSCMA Where MA001= ' " + ID +
" ' " + " and MA003= ' " + PASS + " ' ";
ResultSet rs = stmt.executeQuery(SQL);
rs.first();
if (rs.getString( "MA001 ") == " ")
{
return "Login_ok ";
}
else
{
return "Login_error ";
}
}
catch (Exception e)
{return null;}
}
}
我现在没分了,快给分吧!