Results 1 to 2 of 2
Thread: JAVA: 1 DB, query-
Hybrid View
-
4th August 2006 16:10 #1
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 :
, connect .. . getUserNameFromId getNivoForModule , 2 , .. 2 . 200 200 . MySQL-a exception .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; } }
, ? .. 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
-
5th August 2006 06:59 #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 .
. , .




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in