Share on Google+Share on Google+

dipali
global jdbc file
1 Answer(s)      5 years and 8 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.

Ads

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
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
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  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  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  can u send me the code of jdbc how to join two tables that are in relation
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  how to set classpath for eclipse, java, where to copy jdbc connector
Tutorials   
Java Spring Hibernate Struts Training how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu connectiondetails from vibhu

Ads

 
Advertisement null

Ads