public void login_actionPerformed(ActionEvent e) {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch (ClassNotFoundException ee) {
System.out.println("error in clas forname!");
}
String url="jdbc:microsoft:sqlserver://gyj:1433;DatabaseName=student";
String username = "sa";
String password = "guo";
CallableStatement cstmt=null;
Connection conn=null; String id=username.getText();
char temp[]=password.getPassword();
String tempPass=new String(temp); try
{
conn = DriverManager.getConnection(url, username, password);
cstmt = conn.prepareCall("call student.dbo.userlogin(?.?)");
cstmt.setString(1, id);
cstmt.setString(2, tempPass);
ResultSet rs = cstmt.executeQuery();
boolean flag=rs.next();
if(!flag)
{
JOptionPane.showMessageDialog(this,"登录失败");
}
else
{Frame1 frame=new Frame1();
frame.setVisible(true);} }
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch (ClassNotFoundException ee) {
System.out.println("error in clas forname!");
}
String url="jdbc:microsoft:sqlserver://gyj:1433;DatabaseName=student";
String username = "sa";
String password = "guo";
CallableStatement cstmt=null;
Connection conn=null; String id=username.getText();
char temp[]=password.getPassword();
String tempPass=new String(temp); try
{
conn = DriverManager.getConnection(url, username, password);
cstmt = conn.prepareCall("call student.dbo.userlogin(?.?)");
cstmt.setString(1, id);
cstmt.setString(2, tempPass);
ResultSet rs = cstmt.executeQuery();
boolean flag=rs.next();
if(!flag)
{
JOptionPane.showMessageDialog(this,"登录失败");
}
else
{Frame1 frame=new Frame1();
frame.setVisible(true);} }
不用getText() ,getPassword()那你的输入怎么接受呢?