JDBC connection to database and show results



Share on Google+Share on Google+

JDBC connection to database and show results
1 Answer(s)      9 years ago
Posted in : JDBC

Check if the database connectivity is working fine and show results. Also through an exception if there is any.

View Answers

February 26, 2008 at 4:07 PM


Let us assume a table with 2 coloumns name and slno

name varchar(20)
slno varchar(5)

and go thru this code,i think your problem will get solved.

import java.sql.*;
import java.util.*;
public class Test{
String name=null;
String slno=null;
public static void main (String a[])throws Exception{
Connection conn=null;
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","root");
System.out.println ("Database Connected.");
String sql="select * from test ";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
Collection colc = new ArrayList();
stmt.executeUpdate("INSERT INTO test " + "VALUES ('siva','649')");
System.out.println ("query");

catch (Exception exc){
System.out.println(exc + "<br>");
System.out.println ("Database closed.");
<H3>To check weather there are any contents in the ResultSet
this is done at</H3> if(!(rs.next()))

Thank u
All the best!!


Related Tutorials/Questions & Answers:
Database Connection - JDBC
Database Connection  In java How will be connect Database through JDBC?  Hi Friend, Please visit the following link: http://www.roseindia.net/jdbc/jdbc-mysql/MysqlConnect.shtml Thanks
java database connection - JDBC
java database connection  sir i want to join my project with MS access database. i am making my project in netbeans.please tell me the coding to do... the data into the MS Access database and retrieve the data from the database table
open a connection to a database with exclusive mode with JDBC
open a connection to a database with exclusive mode with JDBC  Is possible to open a connection to a database with exclusive mode with JDBC
open a connection to a database with exclusive mode with JDBC
open a connection to a database with exclusive mode with JDBC  Is possible to open a connection to a database with exclusive mode with JDBC
REQ for connection b/w jdbc and oracle database
REQ for connection b/w jdbc and oracle database    REQ for connection b/w jdbc and oracle database    The Java classes to connect... (OCI or Thin) through the JDBC connection URL. Here are some connection URL
Show results in HTML
Show results in HTML  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values chennai,trichy,kanchipuram... as one value, trichy as one value. and i have to show it in html. how to do
Database connection sql server 2005 - JDBC
Database connection sql server 2005  Hi all i am developing an application in struts and i need to connect database for that application using sql server 2005.. can anyone tell me how to make database connection ..plz help me
display database results
display database results  how to display database results using php
DataBase Connection
DataBase Connection  How to connect java and Oracle 10g? Tell me Jdbc connection
JDBC connection
JDBC connection  ![alt text][1]I got exception in Connecting to a MySQL Database in Java. The exception is ClassNotFoundException:com.mysql.jdbc.Driver wat is the problem
form text box connection with mysql database feild - JDBC
form text box connection with mysql database feild  Respected Sir, What is the coding to connect a form text box field with mysql database table field will you explain me with simple example.. thanking you.. 
Java Jdbc connection
Java Jdbc connection  What are the steps involved for making a connection with a database or how do you connect to a database
connection pooling - JDBC
friend, A connection pool is a cache of database connections maintained by the database. This results connections can be reused when the database receives... commands on a database. It open and maintain a database connection for each user
jdbc connection
"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql:// connection  How to Submit data????   <%-- view... { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection
Connection to Database
I manually make a connection to MySQL database in my web pages? How joomla... is the code how I am connecting to MySQL: I am connection to MySQL database in 2... database tables? Do I need to open one connection to each section? Thank you
database connection
database connection  how to connect the jsp page with database
database connection
database connection  i wanted to no how to connect sqlite database through netbeans? is it posible to connect it to a database that is on a remote pc? thank you
Correctly Open and Close database connection
; } Completely Open and Close A Database Connection Database Connection... and close database connections properly. If any database connection is open... important to close the database connection after it is used. Database connection
database connection
database connection  hi all ready created database table using mysql database,employee payroll,attendance,employee details used database i need how to import and export excel file into database using jsp? pls help me any one
j2me jdbc connection - JDBC
j2me jdbc connection  hello, whn i m importing sql package in mine midlet(tried for both javax.sql.* and java.sql.*;)..itz nt accepting it... hw to get connected to database?????.... plz help me out
JDBC connection pooling
JDBC connection pooling  What is Connection pooling
jdbc connection to java program code - JDBC
jdbc connection to java program code  i want a simple java program that which communicates with oracle database like creating table,insert values and update records in database and show in program output? please take a simple
jdbc connection issues
jdbc connection issues  Hello. kindly pls help in this issue...i... in the database correspondingly. How pls tell me how connect these 11 forms and 11 tables with only one jdbc connection program...if possiable pls post a sample code
Java jdbc connection
Java jdbc connection  Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection
Java-Connection Pool - JDBC
Java-Connection Pool  How can I create a connection pool. My database... is Weblogic 8. Which is the best approach to create a connection pool? ...{ public static void main(String[] args){ Connection con = null; String url
MySql Databse query to fetch results from database
MySql Databse query to fetch results from database  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values... to show it in html. how to do
JDBC Connection Pool
pooling. What is JDBC Connection Pool? The database connection is expensive... database connection in resource pool. You can make your own code for JDBC... database connection and executing the SQL statements Benefits of JDBC Connection
JDBC Database URLs
JDBC Database URLs In this Section, We will discuss about following topics : JDBC Database URL specify a JDBC driver name Connection to a database table JDBC Database URL JDBC Uniform resource locater or 'JDBC URL'
Connection to jdbc - Java Beginners
Connection to jdbc  I need to populate a listbox in jsp with values from Postgresql JDBC. i used the following code... but its not working... can..., We have used Mysql database. Try the following code
connection with database - JSP-Servlet
and the connection with the database using jsp code, I get exceptions that I have... with java code. Is there any other way to establish a connection with database in jsp... a connection with database. Plz reply. Thanks in advance...   Hi
JAVA DATABASE CONNECTION WITH JTABLE  HOw To Load Database Contents From Access Database to JTable without using Vector