Share on Google+Share on Google+

ebuka
how to use dirivers
1 Answer(s)      8 years ago
Posted in : JDBC

Ads

View Answers

May 4, 2009 at 4:05 PM


Hi Friend,

Try the following code :


import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class DisplayAuthors
{
//static final String DRIVER= "com.mysql.jdbc.Driver";
//static final String DATABASE_URL="jbdc:mysql://localhost:3306/test";;

public static void main(String[] args)
{
//new DisplayAuthors();
Connection connection=null;
Statement statement=null;
ResultSet resultSet=null;

try
{
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root";);
//connection=DriverManager.getConnection(DATABASE_URL,"root","root");

statement=connection.createStatement();

resultSet=statement.executeQuery("SELECT * FROM users");

ResultSetMetaData metaData=resultSet.getMetaData();
int numberOfColumns=metaData.getColumnCount();
System.out.println("Authors Table of Books Database:\n");

for(int i=1; i <= numberOfColumns; i++)
System.out.printf("%-8s\t", metaData.getColumnName(i));
System.out.println();

while(resultSet.next())
{
for(int i=1; i<=numberOfColumns; i++)
System.out.printf("%-8s\t", resultSet.getObject(i));
System.out.println();
}
}
catch(SQLException sql)
{
sql.printStackTrace();
}
catch(ClassNotFoundException classNotFound)
{
classNotFound.printStackTrace();
}
finally
{
try
{
resultSet.close();
statement.close();
connection.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}

Thanks
RoseIndia Team









Related Tutorials/Questions & Answers:
how to use dirivers - JDBC
how to use dirivers  i try connecting to a database with this code but i get this ClassNotFoundException, already i have added the path to the connector to my classpath variable. here is the code; import java.sql.Connection
How to use Servlet and Ajax?
How to use Servlet and Ajax?  How to use Servlet and Ajax
Advertisements
how to use calender in php
how to use calender in php  how to put calender in php
How to use AT Commands with J2ME?
How to use AT Commands with J2ME?  How to use AT Commands with J2ME? Thank you for your answer
how to use mouse pressed
how to use mouse pressed   to action mouse clicked
how to use button in array
how to use button in array  plz tell me how to code for button in array
How to Use Collections
How to Use Collections  how to use ArrayList and HashMaps in case of user defined class  Hi Friend, Please visit the following links: http://www.roseindia.net/java/jdk6/ http://www.roseindia.net/javacodeexamples
How to use dojoscript with jsf?
How to use dojoscript with jsf?  Hi all , am new to jsf. can anyone help me out in using dojo script frame work with jsf. how to integrate dojo into jsf. Thanks in advance
how to use setAttribute
how to use setAttribute  how to get following codes using setAttributes in java??? Employee xlink:type="extended" xlink:show="new" xlink:actuate="onRequest
how to use JOptionPane.YES_NO_OPTION
how to use JOptionPane.YES_NO_OPTION  As i said earliar i am making... logging out finally.. i also thinking how to use the input (yes or no ) given... dialog should appear which ask for yes or no . PROBLEM is i dont know how
how to use an editable combobox
how to use an editable combobox   Hello Everyone!!!!!!!! I have a jcombo box with certain values and i want to use it as an editable that means when user will type something in combobox, according to that text only matching item
How to use ajax in jsp?
How to use ajax in jsp?  Hi, How i can access the server-side data in JSP using the Ajax? Thanks   Hi, You can use the Ajax code to access the server side data from JSP page. Check the tutorial Combo Box Using Ajax
how to use jstl tags?
how to use jstl tags?  I installed jstl jar in my libraries. I got the following error in console screen. I need the solution to resolve this uri in web.xml. please help me.......... "The absolute cannot be resolved
How to use bytes
How to use bytes  I have saved my project and uploaded the picture. But when i want to view the picture, there was no picture. I used the method...(rs.getBytes("employeephoto")); How to get the correct answer to view the picture by using
How to use Apache POI?
How to use Apache POI?  Can anyone tell me how to use Apache POI??I went through http://poi.apache.org/ but cannot understand anything.I don't know how to implement.Please help me out.   Download zip file from
How to use between in mysql.
How to use between in mysql.  I want to display records inbetween two dates and also want to use where condition( like and deptname='Pediatry Department').      Syntax: SELECT column_name(s) FROM table_name
how to use - EJB
how to use  I am buiding a Shopping cart and i want to fetch image and its product id from the database(MySql) and fetching of image should be done by JPA
How to use Hibernate get sessionfactory?
How to use Hibernate get sessionfactory?  Hi, How to use hibernate get sessionfactory? Thanks
how to use image tag in jsp
how to use image tag in jsp  How to use image tag in JSP
how to use marathi font in swing?
how to use marathi font in swing?  I want to use marathi language on labels,buttons
How to use session in struts 1.3
How to use session in struts 1.3  i want to know how to use session in Struts specially in logIn authentication
How to use contentType Attribute in JSP?
How to use contentType Attribute in JSP?  Hi, I am learning JSP and now trying to use the contentType Attribute in JSP. tell me how to use the contentType Attribute in JSP? Thanks
how to use group by in nested query
how to use group by in nested query  Hai, How to use group by clause in nested query select statement in subquery i am having where clause.please help me.thanks in advance
How to use the PHP filetype() Function
How to use the PHP filetype() Function  Hi, What is the use of filetype() Function in php programming. Can anyone give any online example of the PHP filetype() Function. Thanks
How to use this keyword in java
How to use "this" keyword in java   ... use this keyword. Here, this section provides you an example with the complete code of the program for the illustration of how to what is this keyword and how
how to use a placeholders - JSP-Servlet
how to use a placeholders  dear sir, how to use and declare a place holder in java? i have to send the following mail Dear [Column 1... be fetch ,so how to use a place holder for this [column ] and also how to get
How to use Date Picker iPhone
How to use Date Picker iPhone  Hi, I am beginner in mobile Application platform. I want to develop a small application in iphone platform to Show current date and display alert view message. So, how to define the date picker
How to use Map in velocity
How to use Map in velocity       This Example shows you how to use map in velocity. The method used in this example are described below:-   1:- Initialize
How to use List in velocity
How to use List in velocity       This Example shows you how to use List in velocity. The method used in this example are described below:-  1:- Initialize
How to use Associations and Joins in Hibernate?
How to use Associations and Joins in Hibernate?  Hi. I am trying to find the examples of Associations and Joins in Hibernate. Give me the code and examples of Associations and Joins in Hibernate. Thanks   Hi, Please
How to use charAt() method in Java?
How to use charAt() method in Java?  Hi, what is the correct way of using chatAt() method in Java? Thanks   The charAt() method in Java is used to find the specific character at specific index. Check the tutorial
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