Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `import java.io.IOException;
- import javax.websocket.OnClose;
- import javax.websocket.OnMessage;
- import javax.websocket.OnOpen;
- import javax.websocket.Session;
- import javax.websocket.server.ServerEndpoint;
- import java.sql.*;
- @ServerEndpoint("/websockett")
- public class Websocket{
- static String m;
- public static void main(String args[]){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/cc","root","");
- Statement stmt=con.createStatement();
- ResultSet rs=stmt.executeQuery("select * from emp");
- while(rs.next()) {
- m=rs.getString(2);}
- con.close();
- }catch(Exception e){ System.out.println(e);}
- }
- @OnMessage
- public void onMessage(String messag, Session session)
- throws IOException, InterruptedException {
- System.out.println("Received: " + messag);
- session.getBasicRemote().sendText(m);
- }
- @OnOpen
- public void onOpen() {
- System.out.println("Client connected");
- }
- @OnClose
- public void onClose() {
- System.out.println("Connection closed");
- }}
Add Comment
Please, Sign In to add comment