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



Home Answers Viewqa JDBC global jdbc file

Have Programming Question? Ask it here!
 
 
 


dipali
global jdbc file
1 Answer(s)      2 years and 11 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
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
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
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
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 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
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
JDBC
JDBC  How to add set of queries in a single query in JDBC
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  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  in class.forname which driver name we are writing for the connection from jdbc to sqlserver 2008
JDBC
JDBC  how to set classpath for eclipse, java, where to copy jdbc connector
jdbc
jdbc  why do we need to load jdbc drivers before connecting to database
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 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
how i can access Microsoft Access database by java program  how i can access Microsoft Access database by java program ? if any package or jar file...("jdbc:odbc:student"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver
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 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
jdbc
how can we call stored procedure using jdbc  how can we call stored procedure using jdbc   Call a Stored Procedure using...(); For more information, visit the following link: JDBC call Stored Procedure
jdbc
how can we set transaction level through jdbc api  how can we set transaction level through jdbc api   Use Connection.setTransactionIsolation(int) to set the desired tansaction level, which takes one of the 5 arguments
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  I can't run my jdbc program because it has error in this line: public static void main(String[] args) the error is:illegal static declaration in inner class would you please let me whats the problem? regards
jdbc
jdbc  hey sir i just wanna have some ppt on jdbc coz have my exams next week and i have not attended any classes coz of job... I m studyng frm niit
jdbc
jdbc  how to update int values of ms-access in jdbc program?   In MS Access database, use Number data type for int values. import... =DriverManager.getConnection("jdbc:odbc:access","",""); Statement st=null; st
jdbc
how can we set transaction level through jdbc api  how can we set transaction level through jdbc api   Use Connection.setTransactionIsolation(int) to set the desired tansaction level, which takes one of the 5 arguments
jdbc
(); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost... information, visit the following link: JDBC Tutorials
jdbc
jdbc  i had written jdbc connection in method and i need to get connection in another class?   import java.sql.*; class... driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/test
jdbc
using jdbc connection   import java.sql.*; public class CreateTable... = DriverManager.getConnection("jdbc:odbc:student"); Class.forName
JDBC - JDBC
JDBC - limitations of jdbc  What are the limitations of JDBC
jdbc - JDBC
Why JDBC   JDBC used for what
JDBC
retrieve the value from database into dropdown list using JDBC SQL 2005  How to retrieve the value from database into dropdown list using JDBC &...").newInstance(); String connectionURL = "jdbc:mysql://localhost:3306/test";; Connection
Advertisements
 

 

 

DMCA.com