我想在浏览器关闭或标签关闭后终止会话.我需要在会话到期后使用Session Listener.But进行一次数据库连接,为此我需要等到会话销毁.
这是会话销毁时执行的代码.
public void sessionDestroyed(HttpSessionEvent event) {
synchronized (this) {
//System.out.println("deletion");
ServletContext application = event.getSession().getServletContext();
sessionCount = (Integer) application.getAttribute("SESSION_COUNT");
application.setAttribute("SESSION_COUNT", sessionCount=sessionCount - 1);
//application.setAttribute("SESSION_COUNT", --sessionCount);
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e) {
System.out.println("" + e);
}
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/raptor1_5", "root", "");
Statement st = connection.createStatement();
st.executeUpdate("update adminlogin set Password='admin' where Username='admin'");
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println("Session Destroyed: " + event.getSession().getId());
System.out.println("Total Sessions after delete: " + sessionCount);
} …
Run Code Online (Sandbox Code Playgroud) 我正在通过Java尝试与我的Cassandra实例的简单连接.我为cqlsh创建了一个'demo'键空间,并在java程序中创建了一个表.代码如下:
使用的罐子:
卡桑德拉-ALL-2.1.2
public class CassandraConnection {
public static void main(String[] args){
String ipAddress="127.0.0.1";
String keySpace="demo";
Cluster cluster;
Session session;
cluster=Cluster.builder().addContactPoint(ipAddress).build();
session=cluster.connect(keySpace);
System.out.println("====================Before insert");
String cqlInsertStmt="insert into users (lastname,age,city,email,firstname) values"
+"('Gopalan',32,'Paramakkudi','murugan@gmail.com','Murugan') ";
session.execute(cqlInsertStmt);
String cqlSelectStmt="select * from users";
ResultSet resultSet=session.execute(cqlSelectStmt);
System.out.println("=================After insert");
for(Row row: resultSet){
System.out.format("%s %s %d %s %s \n", row.getString("firstname"),row.getString("lastname"),row.getInt("age"),row.getString("city"),row.getString("email"));
}
System.out.println("=================After update");
}
}
Run Code Online (Sandbox Code Playgroud)我收到以下错误:
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: ch/qos/logback/core/joran/spi/JoranException
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at com.datastax.driver.core.Cluster.<clinit>(Cluster.java:60) …
Run Code Online (Sandbox Code Playgroud)