Query Mysql

From MyWiki
Revision as of 19:13, 3 November 2014 by George2 (Talk | contribs)

Jump to: navigation, search
Connection con = null;
HttpSession session = request.getSession(true);
Statement stmt = null;                              // For the query
ResultSet rs = null;                                //           
Statement stmt2 = null;                           // For the update
ResultSet rs2 = null;                             //            
String userName = "<username>";
String passWord = "<password>";
String url = "jdbc:mysql://<servername>/argus";
 
try{
    con = DriverManager.getConnection (url, userName, passWord);
    String getIt   =  "SELECT user from sessions where session = '"+session.getId()+"'";
          stmt = con.createStatement();
          rs = stmt.executeQuery(getIt);
          rs.next();
 
             String USERNAME = rs.getString("user");
             //out.println("Logged in as  :"+USERNAME);
             //int length = USERNAME.length();
}
catch(Exception e ) { }