项目结构
所需jar包
proxool.properties
jdbc-0.proxool.alias=mysql_alias jdbc-0.proxool.driver-url=jdbc:mysql://127.0.0.1:3306/tianbao_zzjz jdbc-0.proxool.driver-class=com.mysql.jdbc.Driver jdbc-0.user=liuwentao jdbc-0.password=123456 jdbc-0.proxool.maximum-connection-count=10 jdbc-0.proxool.house-keeping-test-sql=select CURRENT_DATE
Test01
package demo.proxool; import org.logicalcobwebs.proxool.ProxoolException; import org.logicalcobwebs.proxool.configuration.PropertyConfigurator; import java.sql.*; /** * User: liuwentao * Time: 12-6-12 上午10:43 */ public class Test01 { /** * 获得连接 * @return */ public static Connection getConnection() { Connection conn = null; try { PropertyConfigurator.configure("src/proxool.properties"); conn = DriverManager.getConnection("proxool.mysql_alias"); } catch (ProxoolException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return conn; } public static void main(String[] args) { Connection conn = Test01.getConnection(); Statement stmt = null; try { stmt = conn.createStatement(); // String sql_insert = "CREATE TABLE col_link (sitename varchar (20) NULL ,siteurl varchar (50) NULL) "; // stmt.executeUpdate(sql_insert); // stmt.executeUpdate("insert into col_link values('ASP中华网','http://www.aspcn.com')"); // stmt.executeUpdate("insert into col_link values('永远到底有多远','http://xuankong.com')"); // //执行一个insert into语句 // stmt.executeUpdate("update col_link set siteurl='http://www.aspcn.com/xuankong/xuankongt.jpg' where siteurl='http://xuankong.com'"); String sql_query = "select * from zzjz_owner order by id"; ResultSet rs = stmt.executeQuery(sql_query); System.out.println("---------------" + " " + "----------------"); while (rs.next()) { String title = rs.getString("title"); String domain = rs.getString("domain"); /** String title = rs.getString(1); String domain = rs.getString(2); **/ System.out.println(title + "," + domain); } } catch (SQLException e) { e.printStackTrace(); } finally { try { stmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
结果: