Home > Back-end >  Conn. CreateStatement (); An error
Conn. CreateStatement (); An error

Time:12-29

Package com. Dao;

The import com. Db. DBHelper;
The import com. Beans. AdminBean;


import java.util.*;
import java.sql.*;

Public class AdminDao {

//verify login
Public String CheckLogin (String username, String password) {
String id=null;
String SQL="select * from Admin where Admin_Username='" + username +"' and Admin_Password='" + "+"' ";
The Statement stat=null;
The ResultSet rs=null;
The Connection conn=new DBHelper (.) getConn ();
Try {
The stat=conn. CreateStatement ();//the correct line 20
Rs=stat. ExecuteQuery (SQL);
While (rs), next ()) {
Admin_ID id=rs. Get string (" ");
}
}

The catch (SQLException ex) {}
return id;
}
//verify password
Public Boolean CheckPassword (String id, String password) {
Boolean ps=false;
String SQL="select * from Admin where Admin_ID='" + id +"' and Admin_Password='" + "+"' ";
The Statement stat=null;
The ResultSet rs=null;
The Connection conn=new DBHelper (.) getConn ();
Try {
The stat=conn. CreateStatement ();
Rs=stat. ExecuteQuery (SQL);
While (rs), next ()) {
Ps=true;
}
}
The catch (SQLException ex) {}
The return of ps;
}
//access list
Public List GetList (String strwhere, String strorder) {
String SQL="select * from Admin";
if(! (isInvalid (strwhere)))
{
SQL +="where" + strwhere;
}
if(! (isInvalid (strorder)))
{
SQL +="order by" + strorder;
}
The Statement stat=null;
The ResultSet rs=null;
The Connection conn=new DBHelper (.) getConn ();
List List=new ArrayList (a);
Try {
The stat=conn. CreateStatement ();
Rs=stat. ExecuteQuery (SQL);
While (rs), next ()) {
AdminBean cnbean=new AdminBean ();
Admin_ID cnbean. SetAdmin_ID (rs. Get int (" "));
Admin_Username cnbean. SetAdmin_Username (rs. Get string (" "));
Admin_Password cnbean. SetAdmin_Password (rs. Get string (" "));
Cnbean. SetAdmin_Name (rs. Get string (" Admin_Name "));
Admin_Sex cnbean. SetAdmin_Sex (rs. Get string (" "));
Admin_Tel cnbean. SetAdmin_Tel (rs. Get string (" "));
List. The add (cnbean);
}
} the catch (SQLException e) {
e.printStackTrace();
} the finally {
Try {
If (conn!=null)
Conn. Close ();
If (stat!=null)
Stat. The close ();
If (rs!=null)
Rs. The close ();
} the catch (SQLException e) {
e.printStackTrace();
}
}
return list;
}

//obtain the specified ID entity Bean
Public AdminBean GetBean (int id) {
String SQL="select * from Admin where Admin_ID=" + id;
The Statement stat=null;
The ResultSet rs=null;
The Connection conn=new DBHelper (.) getConn ();
AdminBean cnbean=new AdminBean ();
Try {
The stat=conn. CreateStatement ();
Rs=stat. ExecuteQuery (SQL);
While (rs), next ()) {
Admin_ID cnbean. SetAdmin_ID (rs. Get int (" "));
Admin_Username cnbean. SetAdmin_Username (rs. Get string (" "));
Admin_Password cnbean. SetAdmin_Password (rs. Get string (" "));
Cnbean. SetAdmin_Name (rs. Get string (" Admin_Name "));
Admin_Sex cnbean. SetAdmin_Sex (rs. Get string (" "));
Admin_Tel cnbean. SetAdmin_Tel (rs. Get string (" "));

}
} the catch (SQLException e) {
e.printStackTrace();
} the finally {
Try {
If (conn!=null)
Conn. Close ();
If (stat!=null)
Stat. The close ();
If (rs!=null)
Rs. The close ();
} the catch (SQLException e) {
e.printStackTrace();
}
}
Return cnbean;
}

//add
Public void the Add (AdminBean cnbean) {
String SQL="insert into the Admin (";
SQL +="Admin_Name Admin_Username, Admin_Password, Admin_Sex, Admin_Tel";
SQL + values ("=");
SQL +="'" + cnbean getAdmin_Username () + "', '" + cnbean. GetAdmin_Password () +"', '" + cnbean. GetAdmin_Name () + "', '" + cnbean. GetAdmin_Sex () + "', '" + cnbean. GetAdmin_Tel () + "' ";
SQL +=") ";
The Statement stat=null;
The ResultSet rs=null;
The Connection conn=new DBHelper (.) getConn ();
Try {
The stat=conn. CreateStatement ();
Stat. ExecuteUpdate (SQL);
} the catch (SQLException e) {
e.printStackTrace();
} the finally {
Try {
If (conn!=null)
Conn. Close ();
If (stat!=null)
Stat. The close ();
If (rs!=null)
Rs. The close ();
} the catch (SQLException e) {
e.printStackTrace();
}
}
}
//modify
Public void Update (AdminBean cnbean) {
String SQL="update Admin set";
SQL +="Admin_Username='" + cnbean. GetAdmin_Username () +"', ".
SQL +="Admin_Password='" + cnbean. GetAdmin_Password () +"', ".
SQL +="Admin_Name='" + cnbean. GetAdmin_Name () +"', ".
SQL +="Admin_Sex='" + cnbean. GetAdmin_Sex () +"', ".
SQL +="Admin_Tel='" + cnbean. GetAdmin_Tel () +"' ";

SQL +="where Admin_ID='" + cnbean. GetAdmin_ID () +"' ";
The Statement stat=null;
The ResultSet rs=null;
The Connection conn=new DBHelper (.) getConn ();
Try {
The stat=conn. CreateStatement ();
Stat. ExecuteUpdate (SQL);
} the catch (SQLException e) {
e.printStackTrace(); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related