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



Home Answers Viewqa JDBC JDBC connection to database and show results

Have Programming Question? Ask it here!
 
 
 


raghava
JDBC connection to database and show results
1 Answer(s)      6 years and 7 months ago
Posted in : JDBC


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


Advertisement
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
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
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
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
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.. 
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
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 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
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
database connection
database connection  how to connect the jsp page with database
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
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
JDBC connection pooling
JDBC connection pooling  What is Connection pooling
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
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 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
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
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
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 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
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
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
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. Read the JDBC ODBC example. Thanks
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
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
JAVA DATABASE CONNECTION WITH JTABLE  HOw To Load Database Contents From Access Database to JTable without using Vector
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
Server DB connection - JDBC
at the same time but it looks like the java is only picking up the second database. One database is on my localhost and the other one is on server, I want to transfer the data from my localhost database to the database on the server. I have
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 with xslx - JDBC
connection with xslx  hai to all i am not able to connecting to xlsx(2007 excel file) using jdbc?please help me?  Hi Friend, Please visit the following links: http://www.roseindia.net/tutorial/java/poi
Java Jdbc connection
Java Jdbc connection  What are the two major components of JDBC
JDBC connection and SQL Query - JDBC
JDBC connection and SQL Query  Hi, I'm reading a all files one after the other in a directory in java. storing the values in an array of string each time. Now I'm trying to execute a query to insert those values into an oracle
Java Jdbc connection
Java Jdbc connection  What is the use of Class.forName
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-Odbc Connection
JDBC-ODBC Connection       JDBC-ODBC Connection is a JDBC driver that translates the operation... in explaining JDBC Odbc Connection in Java. The code explains you a how creation
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
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
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
Connection pooling - JDBC
Connection pooling  what is meant by connectio pooling and how...;connection pooling concept basically deals with the pool of object. In every... to the container about max and min connection object in the pool
problem in jdbc connection
problem in jdbc connection  when i am trying to insert into apache derby databse using java in netbeans an exceprion is thrown at run time like this:- java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver....what
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
Java Connection to Oracle database
Java Connection to Oracle database  HI I am ubable to connnect jdbc to Oracle database.i had gone to control panel >>Administrative... type properly and the Test Connection failed.So Kindly tell me what to type in TNS
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
 

 

 

DMCA.com