Difference between revisions of "Query Mysql"

From MyWiki
Jump to: navigation, search
(Created page with "<source lang="java"> Connection con = null; HttpSession session = request.getSession(true); Statement stmt = null; ResultSet rs = null; String userName = "<username>"; String...")
 
 
(2 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
Connection con = null;
 
Connection con = null;
 
HttpSession session = request.getSession(true);
 
HttpSession session = request.getSession(true);
Statement stmt = null;
+
Statement stmt = null;                             // For the query
ResultSet rs = null;
+
ResultSet rs = null;                               //         
 +
Statement stmt2 = null;                          // For the update
 +
ResultSet rs2 = null;                            //           
 
String userName = "<username>";
 
String userName = "<username>";
 
String passWord = "<password>";
 
String passWord = "<password>";
Line 19: Line 21:
 
             //out.println("Logged in as  :"+USERNAME);
 
             //out.println("Logged in as  :"+USERNAME);
 
             //int length = USERNAME.length();
 
             //int length = USERNAME.length();
 +
            // Now for the update
 +
            stmt2 = con.createStatement();
 +
            String sql = "update progress set completed='Y',completed_by='"+USERNAME+"' where staffuser='"+INPUT+"'";
 +
         
 
}
 
}
 
catch(Exception e ) { }
 
catch(Exception e ) { }

Latest revision as of 19:19, 3 November 2014

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();
             // Now for the update
             stmt2 = con.createStatement();
             String sql = "update progress set completed='Y',completed_by='"+USERNAME+"' where staffuser='"+INPUT+"'";
 
}
catch(Exception e ) { }