Java SQL PreparedStatement getNewPreparedStatement(String format)

Here you can find the source of getNewPreparedStatement(String format)

Description

get New Prepared Statement

License

Open Source License

Declaration

public static PreparedStatement getNewPreparedStatement(String format) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

import java.sql.SQLException;

public class Main {
    private static final boolean testing = false;
    static Connection connection = getNewConnection();

    public static PreparedStatement getNewPreparedStatement(String format) {
        try {/*from   w w w .  j ava2  s .  com*/
            if (connection == null)
                connection = getNewConnection();
            PreparedStatement s = connection.prepareStatement(format);

            return s;
        } catch (SQLException e) {

        }
        return null;
    }

    private static Connection getNewConnection() {
        Connection connect;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            if (testing)
                connect = DriverManager
                        .getConnection("jdbc:mysql://passwordchanger/test?user=dbUser&password=dbusr");
            else
                connect = DriverManager
                        .getConnection("jdbc:mysql://passwordchanger/production?user=dbUser&password=dbusr");

            return connect;

        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. getGeneratedKey(PreparedStatement ps)
  2. getGenerateKey(PreparedStatement stmt)
  3. getIdentity(PreparedStatement stat)
  4. getLastId(PreparedStatement s)
  5. getLimitedBatchSizePreparedStatement(PreparedStatement pstmt, int maxBatchSize)
  6. getPreparedStatement(Connection conn, String sql)
  7. getPreparedStatement(Connection conn, String sql, List sqlParams, boolean getGeneratedKeys)
  8. getPreparedStatement(String sql)
  9. getPriorID(Connection conn, PreparedStatement stmt)

  10. HOME | Copyright © www.java2s.com 2016