我的原代码如下:
import java.sql.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class linksuper {
//数据连接用的变量!!!
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
String str = "";
boolean linkok = false;
public linksuper(String username,String userpass) {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String URL = "jdbc:odbc:supermarket";
conn = DriverManager.getConnection(URL,"sa","");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String SQL = "select * from userlogin where userid='"+username+"'and 登陆密码='"+userpass+"'";
rs = stmt.executeQuery(SQL);
if(rs.next())
{
linkok = true;
stmt.close();
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public linksuper(String SQL,int i) {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String URL = "jdbc:odbc:supermarket";
conn = DriverManager.getConnection(URL,"sa","");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
if(i==0)
{
linkok = true;
int y= stmt.executeUpdate(SQL);
if(y<0)
JOptionPane.showMessageDialog(null,"更新失败!");
else
JOptionPane.showMessageDialog(null,"更新成功!");
}
else
{
rs = stmt.executeQuery(SQL);
if (rs.next())
{
JOptionPane.showMessageDialog(null,rs.getString(1)); 在这能看到RS的值!
linkok = true;
stmt.close();
conn.close();
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public ResultSet getrs()
{
return rs; 得到的RS中什么也没有!
}
public boolean getlink()
{
return linkok;
}
}
这是为什么啊 怎么才能解决?
各位大哥大姐教小弟一把!