JDBC connection to database and show results

JDBC connection to database and show results

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

Hi,

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;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
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);
if(!(rs.next())){
Collection colc = new ArrayList();
colc.add("null");
System.out.println(colc);
}
else{
stmt.executeUpdate("INSERT INTO test " + "VALUES ('siva','649')");
System.out.println ("query");
}


}
catch (Exception exc){
System.out.println(exc + "<br>");
}
conn.close();
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
Advertisements
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
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
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
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
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
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
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
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
how to show data in database ?
how to show data in database ?  how to show the data in the database to the user in the textbox so that user can modify it and save it again
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
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
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
JDBC connection pooling
JDBC connection pooling  What is Connection pooling
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
"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1...jdbc connection  How to Submit data????   <%-- view... { Class.forName("com.mysql.jdbc.Driver"); Connection con = (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'
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
JAVA DATABASE CONNECTION WITH JTABLE
JAVA DATABASE CONNECTION WITH JTABLE  HOw To Load Database Contents From Access Database to JTable without using Vector
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
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
database - JDBC
database  hai friend, yes i want to use java database connection in eclipse IDE. Thanks in advance
JDBC Connection Pool
pooling. What is JDBC Connection Pool? The database connection is expensive...JDBC Connection Pool In this section we will learn about JDBC Connection Pool and see how to use Apache DBCP for creating the database connection pool. We
show the database values graphical represantation
show the database values graphical represantation   show the database values graphical represantation and auto refresh for every 30 secand displaying in webpage
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
Java jdbc connection
Java jdbc connection  Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection
how to show search results in the same panel of jframe to where search field and button is present..
how to show search results in the same panel of jframe to where search field...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc... where i have to show the search result in the same panel of where search field
JDBC connection
JDBC connection       The JDBC connection implements a connection with database in front end application... we illustrates you JDBC url connection. The current Tutorial helps you
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
JDBC-Odbc Connection
JDBC-ODBC Connection       JDBC-ODBC Connection is a JDBC driver that translates the operation... help you in explaining JDBC Odbc Connection in Java. The code explains you
JDBC Connection and Registration
JDBC Connection and Registration   How to create a JDBC connection..... :-)   JDBC MS Access Database Connectivity: Follow these steps: 1)Go... your java with jdbc code.. It will create table in MS access database. Here
J2ME with Database Connection - MobileApplications
J2ME with Database Connection  I'm using SonyEricssion Java ME SDk for CLDC with WTK2. Can u give me a sample program for Database Connection using MS-Access with MIDlet code
DataBase connection with sql - Struts
DataBase connection with sql  How to connect sql and send db error in struts? what are the tag should i code in struts-confic.xml
server database connection - JSP-Servlet
" in that case how we will get the database connection   Hi Friend...server database connection  sir generally we will connect to the database by using the following steps 1.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver
database connection in struts - Struts
database connection in struts  Connecting database in Struts  in my project 4 table 1.user register 2.login page 3.forgot password 4.welcome page. all in struts but i dont no how sql database connected in struts plz
JDBC Connection Example
; } JDBC Connection Example JDBC Connection is an interface of java.sql.*;  package. An connection object represents a connection with specific database.... To create a connection with database you need to call a method
MySql Databse query to fetch results from database and display it in HTML File
MySql Databse query to fetch results from database and display it in HTML File  Hi. I have a field in database named stages. its datatype is varchar... as one value. and i have to show it in html. how to do
Accessing database with JDBC via Java
Accessing database with JDBC via Java  How to access a database with JDBC via Java application?   Accessing database with JDBC through Java JDBC Example to access Database import java.sql.*; public class JdbcConnect
Java-Connection Pool - JDBC
Java-Connection Pool  How can I create a connection pool. My database is MS SQL server 2000(username-sa, pwd-admin) and my application server is Weblogic 8. Which is the best approach to create a connection pool? Kindly help
choosing best jdbc connection - JDBC
choosing best jdbc connection  among the four types of jdbc which one... is the best type of Jdbc JDBC Net pure Java Driver A native-protocol pure Java driver converts JDBC technology into the network protocol
connection
connection   how to make multiple database connection using jdbc
jdbc odbc connection
jdbc odbc connection  i need a program in java which uses a jdbc odbc connection   Hi, You can create odbc datasource on your windows computer and then access in your Java program.ADS_TO_REPLACE_1 Read the JDBC ODBC
database connection - SQL
-database connection in eclipse IDE? Thanks...database connection  hi friends, This is poornima i want to connect sql server to my eclipse editer how to connect and where i have to write code

Ads