Several JDBC database configuration

2010-08-01  来源:本站原创  分类:Java  人气:161 

Jdbc or very recently that used mainly in high efficiency Haha I generally like to write to write jdbc base class first to get the connection directly through the constant

package com.demo.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class BaseJdbcDao {

        // The connection string for the driver
        public static final String DRIVER="com.microsoft.sqlserver.SQLServerDriver";
        // Connection  URL
        public static final String URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=news";
        // Database user name
        public static final String NAME="sa";
        // Database password
        public static final String PARSWORD="123";
        // The connection object
        public static Connection con=null;

        public static PreparedStatement pstmt=null;
        // The result set
        public static ResultSet rs=null;

        /**
         *  Gets the link
         *
         * @return
         * @throws ClassNotFoundException
         * @throws SQLException
         */
        public Connection getCon() throws ClassNotFoundException, SQLException{
                Class.forName(DRIVER);
                con=DriverManager.getConnection(URL,NAME,PARSWORD);
                return con;
        }

        /**
         *  Close method
         *
         * @param con
         * @param pstmt
         * @param rs
         * @throws SQLException
         */
        public void closeAll(Connection con,PreparedStatement pstmt,ResultSet rs) throws SQLException{
                if(rs!=null){
                        rs.close();
                }
                if(pstmt!=null){
                        pstmt.close();
                }
                if(con!=null){
                        con.close();
                }
        }

}

The second area through the properties file to read connection information is just not the same as the reading connection information

First, we must first add the items inside. Properties file, and then to read. Properties (attributes) file in the project, we usually put them in the default path (src) file which was created under the
driver = com.microsoft.sqlserver.SQLServerDriver
url = jdbc: microsoft: sqlserver: / / localhost: 1433; DatabaseName = news
user = sa
password = 123
When the Properties class is called load () method, the system to. Properties contents of the file loaded into memory steps:
1.InputStream is = getClass (). GetResourceAsStream ("file name");
2. Call the load method of Properties
3.getProperty ("property name"); here is that before the property name. Properties defined in the character of the equal sign in front of
4. Through the String variable to the receiver such as: String Driver = load (getClass (). GetResourceAsStream ("file name")). GetProperty ("driver");
So to get connection information

These are but two kinds of connections De France in different configurations, each time only one connection is open or closed, it also caused us to think, there is no connection at initialization time Chuangjian Yidingshuoliang of Shu Juku connection, Suoyiyouliao connection Chi Oh so we have a database connection pool simply removed from the connection pool idle database connections to access the database when the program ended, then the database connection back into connection pool, so the efficiency can be improved access to the database how to obtain the database connection pool connection then:
1.Context ic = new InitialContext ();
2.DataSource source = (DataSource) ic.lookup ("java: comp / env / jdbc / books");
3.Connection con = source.getConnection ();
We are through the JNDI technology to access the DataSource
So we have to go to configure the JNDI in Tomcat's root directory \ config \ context.xml to add information
<Resource name = "jdbc/B2CShop" auth = "Container" type = "javax.sql.DataSource" maxActive = "100" maxIdle = "30" maxWait = "10000" username = "sa" password = "" driverClassName = " com.microsoft.sqlserver.jdbc.SQLServerDriver "url =" jdbc: sqlserver: / / localhost: 1433; DatabaseName = news "/>
In the sql driver into Tomcat's lib directory inside the folder with the source data is in fact the container to create the Tomca

相关文章
  • Several JDBC database configuration 2010-08-01

    Jdbc or very recently that used mainly in high efficiency Haha I generally like to write to write jdbc base class first to get the connection directly through the constant package com.demo.dao; import java.sql.Connection; import java.sql.DriverManage

  • Eclipse works the Oracle Database Configuration 2009-05-08

    Oracle database configuration Flex + Java project 1. A first step, the reference to "flex, step by step. Doc" files, set up felx works. 2. . The second step, with reference to "set up spring + hibernate + webflex works. Doc", give Flex

  • SQL Server JDBC Driver configuration 2008-10-03

    SQL Server JDBC Driver configuration keywords: sql server jdbc driver configuration method a and download drivers. Download: http://download.microsoft.com/download/8/B/D/8BDABAE2-B6EA-41D4-B903-7916EF3690EF/sqljdbc_1.2.2323.101_enu.exe First, downloa

  • jetspeed installation and database configuration 2008-06-01

    Installation: 1. First to http://portals.apache.org/jetspeed-2/getting-started-installer.html download jetspeed install jar package. demo versions of some of the content of more comprehensive. (The following two steps to be carried out is to download

  • JDBC database connection pool Statment 2010-09-08

    1. Foreword   database applications, in many software systems are often used, is indispensable for the development of supporting large-scale systems. But if not well managed database resources (such as: failure to make timely recovery of the databa

  • JDBC database connection pool and the principle of achieving 2010-11-07

    1. Introduction Database applications, in many software systems are often used, is indispensable to the development of supporting large-scale systems. But if not well managed database resources (such as: failure to make timely recovery of the databas

  • A simple implementation of JDBC database connection pool 2011-01-06

    Of :snapbug From :CSDN   directory :   1. Introduction   2. Connection pool technology background   2.1 JDBC   2.2 JDBC Connection Pool   2.3 connection pool (ConnectionPool) And resource management   3. Simple JDBC Implementation of co

  • JDBC database connection pool implementation and principles 2010-11-07

    1 Introduction Database applications, many software systems are often used, is the development of large systems indispensable aid. But if not well managed database resources (such as: failure to make timely recovery of the database cursor (ResultSet)

  • Spring + Hibernate Mysql read and write within the framework of separation master-slave database configuration (on) 2011-04-08

    Reproduced: http://lujia35.iteye.com/blog/969466 Introduced in the mysql database to read and write separate spring, hibernate framework configuration. 1.mysql connection profile jdbc.properties master .*.* represents the primary database connection

  • Encyclopedia of JDBC database connectivity 2009-07-15

    JDBC database connections commonly used title written zlyperson (original) Keyword JDBC Sybase MySQL SQLServer PostgreSQL Oracle ODBC 1. MySQL (http://www.mysql.com) mm.mysql-2.0.2-bin.jar / Class.forName ( "org.gjt.mm.mysql.Driver"); cn = Drive

  • JDBC database connections commonly used written 2009-11-18

    JDBC database connections commonly used title written zlyperson (original) Keyword JDBC Sybase MySQL SQLServer PostgreSQL Oracle ODBC 1. MySQL ( http://www.mysql.com) mm.mysql-2.0.2-bin.jar / Class.forName ( "org.gjt.mm.mysql.Driver"); cn = Driv

  • JDBC database connection with several steps 2010-04-18

    JDBC database connection using the following steps: (1) first in the application load JDBC driver. Typically use Class.forName () method of loading point to note is to set a good classpath classpath, ensure that the JDBC driver in the class path. Ora

  • sybase database configuration experience exchange 2010-06-25

    Sybase configuration parameters sp_configure 'max online engines', 4 go - Configure the number of boot cpu sp_configure 'number of engines at startup', 4 go - Configure the maximum memory number sp_configure 'max memory', 2097151 go - The largest all

  • Oracle database configuration and optimization of SQL statements / * + rule * / 2010-06-27

    Oracle database configuration and optimization of SQL statements. 2 Oracle Database Configuration 2.1 The key factors affecting the efficiency of SQL and configuration: Oracle database, set a great impact on their performance, such as the Shared Pool

  • Dynamic database configuration 2010-11-04

    Rails database configuration file config / database.yml is a YAML file. However, before it become a YAML parser, it is to use Erb pretreatment operation. This means that you can be implanted in the Ruby code to such documents, like your view as a tem

  • With the Database Configuration Assistant (Database Configuration Assistant) to create the database 2010-12-23

    Start with the Database Configuration Assistant command line cmd-> Configuration Assistant directory (eg: C: \ oracle \ product \ 10.2.0 \ db_1 \ BIN) -> dbca -> Next -> Create Database -> determine whether the transaction or data warehouse

  • MySQL Cluster: master-slave database configuration for query load 2011-07-25

    Doing web application system, if the database performance bottlenecks occurred, and you are using the MySQL database, then consider using a database query clustering approach to achieve load the. Because in general, any system updates the database qu

  • Using Database Configuration Assistant (Database Configuration Assistant) to create a database 2010-12-23

    Start with the Database Configuration Assistant command line cmd-> Configuration Assistant directory (eg: C: \ oracle \ product \ 10.2.0 \ db_1 \ BIN) -> dbca -> Next -> Create Database -> identified as transaction processing or data wareho

  • JDBC database connection principle 2011-01-18

    JDBC database connection: Java Database Connectivity, (Java Database Connectivity, referred to as JDBC) is used to standardize the Java language client how to access the database application program interface, provides such data in the database query

  • jdbc database transaction isolation level view 2011-02-12

    jdbc database transaction isolation level view Database transaction 2009-07-04 15:22:53 read 111 comments 0 Word Count: Subscribe public static void main (String [] args) { String driverClass = "net.sourceforge.jtds.jdbc.Driver"; / / DriverClass