Results 1 to 2 of 2

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User spritable's Avatar
    Join Date: Oct:2001
    Location:
    Posts: 445

    JAVA: 1 DB, query-

    . ( SELECT-a ).

    Servlet :

    package myClass;

    Code:
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    
    public class sqlBean {
    
        private static String DBUrl = "jdbc:mysql://localhost:3306/DB?user=root&password=root&characterEncoding=cp1251";
        private Connection conn = null;
    
    	public Statement connect() 
    		throws SQLException, Exception {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection(DBUrl);
            Statement stmt = conn.createStatement();
            return stmt;
        }
    
        public void disconnect(Statement stmt) {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException sqlEx) {
                	// ignore 
                }
    			stmt = null;
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException sqlEx) {
                	// ignore 
    			}
    			conn = null;
            }
        }
    }

    Servlet :

    Code:
    package myClass;
    
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    	
    public class usersBean {
    	private sqlBean mydb = new sqlBean();
    
    	public String getUserNameFromId(String nameId) {
    		String tmp = "$";
    		try {
    			Statement stmt = mydb.connect();
    
    	        ResultSet rs = stmt.executeQuery("select USERREALNAME from users where ID='"+nameId+"'");
    	        rs.next();
    	        tmp = rs.getString("USERREALNAME");
    
    	        rs.close();
    	        mydb.disconnect(stmt);
    		} catch (Exception ex) {
    			// error
    		}
    		return tmp;
    	}
    
    	public boolean getNivoForModule(String accessModul, int accessNivo) {
    		boolean tmp = false;
    		try {
    			Statement stmt = mydb.connect();
    
    	        ResultSet rs = stmt.executeQuery("select "+accessModul+" from accesslevel where NIVO='"+accessNivo+"'");
    	        rs.next();
    	        if ((rs.getInt(accessModul))==1) {
    	        	tmp = true;
    	        }
    
    	        rs.close();
    	        mydb.disconnect(stmt);
    		} catch (Exception ex) {
    			// error
    		}
    		return tmp;
    	}
    
    }
    , connect .. . getUserNameFromId getNivoForModule , 2 , .. 2 . 200 200 . MySQL-a exception .

    , ? .. 2- , .

    . ephemeral ports socket connection timeout 240 30. .
    i7 9700K | Noctua NH-D14 | Asus ROG Strix Z390-F | Vengeance LPX 16GB 3200 | Asus TUF 4070 Ti | couple of M.2 | Sound Blaster Z | CM V850 | Be Quiet Silent Base 601 | Asus ROG Swift PG278Q | Razer Blackwidow | Razer Viper | Sennheiser GSP 600

  2. #2

    Join Date: Feb:2005
    Location: somewhere
    Posts: 141
    , - Tomcat. Tomcat- ( ) connection pool. . ( ) . . .

    :
    1. connection pool. . .
    2. -.
    3. pool-.

    . . . , . , , ..

    , .

    connection pool-, ( application , application ) stand-alone, c3p0, Apache Foundation .

    . , .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |