Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC global jdbc file
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


dipali
global jdbc file
1 Answer(s)      3 years and 4 months ago
Posted in : JDBC


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.


Advertisement
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
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
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
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
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
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
PHP Variable Global
PHP Global Variables PHP Global variable are the variables which can be used... can use global variable in different-different ways, For example : PHP Global...;; $num2 = "6"; function multi() { global $num1,$num2; $num2
Global Positioning System Advantages
Global Positioning System Advantages Global Positioning System has many... car and even a mobile phone has been made easy by global positioning system... are stored in a database. One of the very noted benefits of the Global
Global style in Flex4
Global style in Flex4: You can set the style using global selector. It set... you can see how we can use global style using simple way and setStyle...; <!-- Global Style --> <fx:Style> @namespace s
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
Basics of global positioning system
Basics of global positioning system The Global Positioning system is slowly and steadily making a niche for itself. More and more number of people... in the number of people using Global positional system technology. It is basically
Global Positioning System
Global Positioning System       Brief History :-The Global positioning System (GPS), formally known as the Navstar Global Positioning System, was first time used by united states
TheBroth, The Global Mosaic
TheBroth, The Global Mosaic       TheBroth is a browser-based massively multiplayer collaborative art... time global mosaic, made of 1000 colorful tiles. Read full Description
Basics of Global Positioning System
Basics of Global Positioning System       Origin & History: The Global Positioning System is originally a part of Navigation System with Timing and Range (NAVSTAR
Java Array Values to Global Varibles - Java Beginners
Java Array Values to Global Varibles  I am working on a program that provides users with 3 loan options. If global variables rate and periods... the following code..which is passing that global variables value into the method
jdbc
jdbc  Hai , Give a steps for jdbc connectivity
jdbc
jdbc  display the records using index in jdbc
JDBC
JDBC  why we use batch in jdbc
JDBC
JDBC  How to add set of queries in a single query in JDBC
Global Positioning system facts
Global Positioning system facts Global positioning system facts are centred on the applications and uses of GPS systems. GPS systems are the easiest and most accurate ways to track vehicles, mobile phones and various other objects
jdbc
jdbc  how can i store the image file and retrive the images from... = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); File imgfile = new File("C:/flower.jpg"); FileInputStream fin = new
Jdbc
Jdbc  A java program with jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
jdbc
jdbc  is it possible to use doget & dopost method with jdbc to call in a servlet programe
JDBC
JDBC  in class.forname which driver name we are writing for the connection from jdbc to sqlserver 2008
jdbc
jdbc   how to write program to save data and retrieve data from the form in Java
jdbc
jdbc  please tell me sir.i dont know JDBC connection and how to create table in database
JDBC
JDBC  can u send me the code of jdbc how to join two tables that are in relation
Advertisements
 

 

 

DMCA.com