global jdbc file

global jdbc file

hi, I want to create a global connection file by using function like getConnection(),startConnection(), and stopConnection() etc. so anybody from my team can access that class file. can anybody help me out for the same.

Thanks in advance.

View Answers

August 24, 2011 at 2:04 PM

import java.sql.*;

class DatabaseConnection{
  public static Connection getConnection() throws Exception {
    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/test";
    String username = "root";
    String password = "root";
    Class.forName(driver);
    return DriverManager.getConnection(url, username, password);
  }
  }
public class GetConnection {
  public static void main(String[] args) throws Exception {
    Connection conn = DatabaseConnection.getConnection();
    Statement st = conn.createStatement();
    ResultSet rs = st.executeQuery("SELECT * FROM data");
    while(rs.next()){
    System.out.println(rs.getString("name")+" \t "+rs.getString("address"));
    }
    rs.close();
    st.close();
    conn.close();
  }
}









Related Tutorials/Questions & Answers:
global jdbc file
global jdbc file  hi, I want to create a global connection file.... so anybody from my team can access that class file. can anybody help me out... driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost
xml configuration file - JDBC
a xml configuration file . We have mysql database in some other system. I have to access the data from different system. For this jdbc connectivity how to create a xml file. Please help me out. Thank you  Hi Friend, Try
Advertisements
exe file creation - JDBC
exe file creation   hi i have done a project in java swings.project name is format migrator.means db migrator. now my aim is create EXE FILE for my project. pls do consider
excel file using JDBC java.?
excel file using JDBC java.?  hey, i am a telecomm. engineer , and i am try to develop a tool which reads from a excel file and then appends the same... used JDBC ODBC to read from excel file. i am not able to append it using
read text file and store the data in mysql - JDBC
read text file and store the data in mysql  when we store the data in mysql table from text file its store the data from new line to new column. how to store the data in different column from a single line of text file
upload ,download and update file document - JDBC
upload ,download and update file document   hi sir.i am creating one application in jsp in which i need to upload the word document file which... to upload the word file: 1)page.jsp Display file upload form
Access Excel file through JDBC
Access Excel file through JDBC In this section, you will learn how to access excel file through Jdbc and display records in JTable. As you know Excel comes with an ODBC driver, so we are using JDBC-ODBC bridge driver to connect jdbc
global variable in objective c
global variable in objective c  Declaring global variable in objective c
creating a global variable with php
creating a global variable with php  Is it possible to create a variable to declare as global in case of database connectivity?   Yes... below.. function processlogin($username, $password){     global $database
Expport data into CSV File using JDBC in Servlet
into CSV File using JDBC in Servlet   ... into CSV file using JDBC in Servlet. We have created  file "JdbcCsvFile.java" to export data from database in to CSV file. Brief
global data science
global data science  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: global data science... the topic "global data science". Also tell me which is the good training
global certificate in data science
global certificate in data science  Hi, I am beginner in Data...: global certificate in data science Try to provide me good examples or tutorials links so that I can learn the topic "global certificate in data science"
data science global certification
data science global certification  Hi, I am beginner in Data Science... science global certification Try to provide me good examples or tutorials links so that I can learn the topic "data science global certification"
ModuleNotFoundError: No module named 'global_identity'
ModuleNotFoundError: No module named 'global_identity'  Hi, My... named 'global_identity' How to remove the ModuleNotFoundError: No module named 'global_identity' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'global_opt'
ModuleNotFoundError: No module named 'global_opt'  Hi, My Python... 'global_opt' How to remove the ModuleNotFoundError: No module named 'global_opt' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'global_identity'
ModuleNotFoundError: No module named 'global_identity'  Hi, My... named 'global_identity' How to remove the ModuleNotFoundError: No module named 'global_identity' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'global_opt'
ModuleNotFoundError: No module named 'global_opt'  Hi, My Python... 'global_opt' How to remove the ModuleNotFoundError: No module named 'global_opt' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'global-py'
ModuleNotFoundError: No module named 'global-py'  Hi, My Python... 'global-py' How to remove the ModuleNotFoundError: No module named 'global... have to install padas library. You can install global-py python with following
ModuleNotFoundError: No module named 'global-utilities'
ModuleNotFoundError: No module named 'global-utilities'  Hi, My... named 'global-utilities' How to remove the ModuleNotFoundError: No module named 'global-utilities' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'global-utils-88'
ModuleNotFoundError: No module named 'global-utils-88'  Hi, My... named 'global-utils-88' How to remove the ModuleNotFoundError: No module named 'global-utils-88' error? Thanks   Hi, In your python
PHP Global Variable
PHP  Global Variable To access global variable in PHP we need to use global keyword or $GLOBALS associative array global is a keyword which helps us to access the globally declared variable. There is no limit to use global
not able to run in gcj file - JDBC
JDBC
JDBC  why we use batch in jdbc
jdbc
jdbc  display the records using index in jdbc
jdbc
jdbc  Hai , Give a steps for jdbc connectivity
JDBC
JDBC  How to add set of queries in a single query in JDBC
jdbc
jdbc  please tell me sir.i dont know JDBC connection and how to create table in database
jdbc
jdbc   how to write program to save data and retrieve data from the form in Java
jdbc
jdbc  why do we need to load jdbc drivers before connecting to database
JDBC
JDBC  how to set classpath for eclipse, java, where to copy jdbc connector
JDBC
JDBC  in class.forname which driver name we are writing for the connection from jdbc to sqlserver 2008
jdbc
jdbc  is it possible to use doget & dopost method with jdbc to call in a servlet programe
Jdbc
Jdbc  A java program with jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
JDBC
JDBC  can u send me the code of jdbc how to join two tables that are in relation
jdbc - JDBC
Why JDBC   JDBC used for what
JDBC - JDBC
JDBC - limitations of jdbc  What are the limitations of JDBC
jdbc
jdbc define batch updates  define batch updates?exp   JDBC... links: http://www.roseindia.net/jdbc/Jdbc-batch-update.shtml http://www.roseindia.net/tutorial/java/jdbc/batchupdateresultsetexample.html
jdbc
jdbc  Write a web based student registration application where the students can register online with their enrollment no. You are required to use JSP, Servelet and JDBC
Export Data into CSV file uing JDBC in JSP
Export Data into CSV file uing JDBC in JSP       CSV file : A CSV file is commonly known as a Comma Delimited File or a Character Separated File.ADS_TO_REPLACE_1 Step : 1
JDBC
JDBC save a data in the database  I need a code to save a data... between java and mysql using JDBC and saves the data into the database. import... con = null; String url = "jdbc:mysql://localhost:3306/"; String db
JDBC
JDBC code to save a data in the database  I need a code to save... the connection between java and mysql using JDBC and saves the data into the database...!"); Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String db
ModuleNotFoundError: No module named 'aws-cdk.aws-dynamodb-global'
ModuleNotFoundError: No module named 'aws-cdk.aws-dynamodb-global'  ...: No module named 'aws-cdk.aws-dynamodb-global' How to remove the ModuleNotFoundError: No module named 'aws-cdk.aws-dynamodb-global' error? Thanks
ModuleNotFoundError: No module named 'global-forecast-validation'
ModuleNotFoundError: No module named 'global-forecast-validation'  Hi...: No module named 'global-forecast-validation' How to remove the ModuleNotFoundError: No module named 'global-forecast-validation' error? Thanks
ModuleNotFoundError: No module named 'global-land-mask'
ModuleNotFoundError: No module named 'global-land-mask'  Hi, My... named 'global-land-mask' How to remove the ModuleNotFoundError: No module named 'global-land-mask' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'global_lru_cache'
ModuleNotFoundError: No module named 'global_lru_cache'  Hi, My... named 'global_lru_cache' How to remove the ModuleNotFoundError: No module named 'global_lru_cache' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'HZ-Redis-Global'
ModuleNotFoundError: No module named 'HZ-Redis-Global'  Hi, My... named 'HZ-Redis-Global' How to remove the ModuleNotFoundError: No module named 'HZ-Redis-Global' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'odoo11-addon-account-global-discount'
ModuleNotFoundError: No module named 'odoo11-addon-account-global-discount...: ModuleNotFoundError: No module named 'odoo11-addon-account-global-discount' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-account-global
ModuleNotFoundError: No module named 'odoo11-addon-account-global-discount'
ModuleNotFoundError: No module named 'odoo11-addon-account-global-discount...: ModuleNotFoundError: No module named 'odoo11-addon-account-global-discount' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-account-global
ModuleNotFoundError: No module named 'odoo11-addon-base-global-discount'
ModuleNotFoundError: No module named 'odoo11-addon-base-global-discount' ...: ModuleNotFoundError: No module named 'odoo11-addon-base-global-discount' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-base-global-discount'
ModuleNotFoundError: No module named 'odoo11-addon-base-global-discount'
ModuleNotFoundError: No module named 'odoo11-addon-base-global-discount' ...: ModuleNotFoundError: No module named 'odoo11-addon-base-global-discount' How to remove the ModuleNotFoundError: No module named 'odoo11-addon-base-global-discount'

Ads