general wording of the database jdbc connection

2010-08-15  来源:本站原创  分类:Tech  人气:165 

package com.daqing.jdbc;

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

/**
 *  This method is not new instances
 * @author Administrator
 *
 */
public final class A0101JdbcUtils {

        private static final String url = "jdbc:mysql://127.0.0.1:3306/jdbc";
        private static final String user = "root";
        private static final String password = "root";

        private A0101JdbcUtils(){
        }

        static {
                try {
                        Class.forName("com.mysql.jdbc.Driver");
                } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                        throw new ExceptionInInitializerError(e);
                }
        }

        public static Connection getConnection() throws SQLException{
                return DriverManager.getConnection(url, user, password);
        }

        public static void free(ResultSet rs, PreparedStatement ps, Connection conn){
                try {
                        if(rs!=null){
                                rs.close();
                        }
                } catch (SQLException e) {
                        System.out.println("ResultSet Close the exception occurred  ...");
                } finally {
                        if(ps!=null){
                                try {
                                        ps.close();
                                } catch (SQLException e) {
                                        System.out.println("PreparedStatement Close the exception occurred  ...");
                                } finally {
                                        if(conn!=null){
                                                try {
                                                        conn.close();
                                                } catch (SQLException e) {
                                                        System.out.println("Connection Close the exception occurred  ...");
                                                }
                                        }
                                }
                        }
                }
        }
}
相关文章
  • general wording of the database jdbc connection 2010-08-15

    package com.daqing.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; /** * This method is not new instances * @author Administrator * */ public

  • Database JDBC Connection wording used 2010-09-27

    Database JDBC Connection used wording 1. MySQL (http://www.mysql.com) mm.mysql-2.0.2-bin.jar Class.forName ("org.gjt.mm.mysql.Driver"); cn = DriverManager . getConnection ("jdbc: mysql: / / MyDbComputerNameOrIP: 3306/myDatabaseName", s

  • means the list of database jdbc connection 2011-01-24

    means the list of database jdbc connection The following lists the various databases that use JDBC connections, it can be used as a guide. 1, Oracle8/8i/9i database (thin model) Class.forName ("oracle.jdbc.driver.OracleDriver"). NewInstance ();

  • The java database jdbc connection db2 2010-12-23

    / ** Learn the basics of ** / For Java programmers, DB2 offers two application programming interface (API): JDBC and SQLJ. JDBC: JDBC driver into the old / CLI driver <db2java.zip> and the new Universal JDBC Driver (Universal JDBC Driver) <db2jcc

  • Mainstream database JDBC connection 2011-07-13

    Java Database Connectivity (JDBC) by a group of Java programming language classes and interfaces. JDBC for tool / database developers with a standard API, so that they can use pure Java API to write database applications. However, each developer's in

  • Common database JDBC connection wording Daquan 2011-10-20

    1. MySQL (http://www.mysql.com) mm.mysql-2.0.2-bin.jar Class.forName ("org.gjt.mm.mysql.Driver"); cn = DriverManager.getConnection ("jdbc: mysql: / / MyDbComputerNameOrIP: 3306/myDatabaseName", sUsr, sPwd); 2. PostgreSQL (http://www.de

  • Install and start the HSQLDB database JDBC connection 2011-02-12

    HSQLDB is a lightweight pure Java open source relational database system. Because the HSQLDB lightweight (small footprint), easy to use, support for memory operation mode, etc., HSQLDB is widely used development environment and some small systems. In

  • Database JDBC Connection 2010-04-23

    Download the appropriate database driver jar package to write code to modify the database information is not very standard package is not good Oh package com.test.db; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Prepared

  • Oracle Database JDBC Connection 2010-05-26

    Connection method: 1. MyEclipse import Oracle's JDBC driver package (oracle \ jbdc \ lib \ classes12.jar); 2. Driver: oracle.jdbc.driver.OracleDriver 3. Connect Address: jdbc: oracle: thin: @ localhost: 1521: database name TestJDBC.java: view sourcep

  • Mysql database jdbc connection garbled solution 2010-09-24

    1. View the database encoding format: show variables like 'character%'; 2. Set the connection encoding format: jdbc: mysql: / / 127.0.0.1:3306 / databaseName? useUnicode = true & characterEncoding = gbk & zeroDateTimeBehavior = convertToNull 3. To

  • MySQL database JDBC connection 2010-10-23

    package com.digican.db; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class SQLdb { private static String user = "root"; private stat

  • Common database JDBC connection 2010-12-08

    1, Oracle8/8i/9i database (thin model) Class.forName ("oracle.jdbc.driver.OracleDriver"). NewInstance (); String url = "jdbc: oracle: thin: @ localhost: 1521: orcl"; / / Orcl SID for the database String user = "test"; String

  • five kinds of database jdbc connection 2011-05-06

    package cn.com.db; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DBconn { public static Connection connDB_mysql () throws ClassNotFoundException {/ / mysql Class.forName ("com.mysql.jdbc.Driver&

  • H2 Database JDBC Connection 2010-04-28

    h2 database is a very lightweight relational database, I usually uses the staff to do Demo, a new framework for assessment. Very light use. A look at how h2 jdbc access it, the following information from the official website. H2 JDBC Driver and URL I

  • JDBC Connection database skills experience highlights 2010-04-02

    Java Database Connectivity (JDBC) by a group of Java programming language with the class and interface. JDBC as a tool / database developers with a standard API, so that they can use pure Java API to write database applications. However, the interfac

  • Oracle database, common data types and jdbc connection string 2010-05-04

    1. Oracle database data types commonly used in varchar2 (length) variable length strings char (length) fixed length number () that an integer or floating point number (8) number (8,2) clog character large object blog binary large object jdbc connecti

  • jdbc connection access database 2010-06-08

    package com.core; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class Mytest { public static void main(String[] args) throws Exception { Connection con=null ; try { Class.forName("sun.jdbc.odbc.J

  • JDBC connection is not on the database 2010-08-05

    This evening there was a special issue of depressed, has been tested and hard about the project can not even run because the connection is not on the database, in order to solve this problem after another in a long time, and I am Wohuo, but the probl

  • JDBC connection Access database insert failed Memo type field 2010-11-30

    In the Access database using JDBC connection, Memo type field into the failure, error: ODBC Microsoft Access Driver] invalid precision value. Can be solved by trying the following. Solution: Method 1. The memo into the last field. Method 2. To ensure

  • JDBC Connection database instance (Oracle \ SQLServer \ MySQL drivers) 2010-10-22

    Using JDBC to connect to the database, the basic steps are similar, but different between the URL of the database is somewhat different. The basic steps can be divided into the following: 1, load the appropriate database JDBC driver. 2, using the dri