Home Answers Viewqa JDBC JDBC connection to database and show results

 
 


raghava
JDBC connection to database and show results
1 Answer(s)      5 years and 3 months 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


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 Pages:
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
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
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
connection
connection   how to make multiple database connection using jdbc
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
DataBase Connection
DataBase Connection  How to connect java and Oracle 10g? Tell me Jdbc connection
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
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
JDBC - JDBC
JDBC connection to database and show results  Check if the database connectivity is working fine and show results. Also through an exception... Exception{ Connection conn=null; try{ Class.forName
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 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
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
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 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
Jdbc Mysql Connection Url
JDBC Mysql Connection Url      ... JDBC Mysql Connection. In this program, the code explain the JDBC url and string connection that helps you in connecting between url and database. For this we
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
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
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
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-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-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
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
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
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 Components
and retrieve results and updation to the database. The JDBC API is part of the Java... Database Connectivity. For connectivity with the database we uses JDBC. It establish connection to access the database. This provides a set of classes
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
JDBC - Java Database Connectivity Tutorial
JDBC. It establish connection to access the database. This provides a set... connection between program and database by using connection interface and JDBC... JDBC - Java Database Connectivity Tutorials  
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
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
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
java database connection
java database connection  package com.tsi.constants; public class Constant { public static final String DRIVER = "oracle.jdbc.driver.OracleDriver"; public static final String DBURL = "jdbc:oracle:thin
java database connection
java database connection  package com.tsi.constants; public class Constant { public static final String DRIVER = "oracle.jdbc.driver.OracleDriver"; public static final String DBURL = "jdbc:oracle:thin
How to show data from database in textbox in jsp
How to show data from database in textbox in jsp   How to show data from database in textbox in jsp   Here is an example that retrieve...(); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test
java database connection - Struts
; value="jdbc:mysql:///database_name?autoReconnect=true"...java database connection  how to connect a database in struts program?  First Add two jar file1> commons-dbcp-1.2.x.jar2> mysql
connection database error
connection database error  import java.awt.EventQueue; // import...{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:NWIND
error oracle database connection?
error oracle database connection?  hi now i am trying to connect oracle database and also insert my data into table, but it's not working.. I created...; PreparedStatement stmt=null; Connection con =null; ResultSet rs=null
jdbc - JDBC
in a database System.out.println("MySQL Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost:3306/"; String dbName... want to get the table count in a database or row count in a table? if u want
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
DriverClass hibernate mysql connection.
-factory> <!-- Database connection settings --> <...;/property> <!-- JDBC connection pool (use the built-in) -->... the connection url as- <property name="connection.url">jdbc:mysql://localhost
JDBC connection closed.. - Java Beginners
JDBC connection closed..  if the connections r closed..the values... the connection (jdbc) is closed)   Hello, As i know after... that if you make the database connection and fetch the data and store it in the HashMap
database - JDBC
database  hai friend, yes i want to use java database connection in eclipse IDE. Thanks in advance
database
or not. If it is already exist in database, then show a message 'Already exists..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost...database  i am created one table in mysql database with one
Displaying search results in same panel of gridview in same jframe window.
("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql...Displaying search results in same panel of gridview in same jframe window... search and see the results in the same panel of the Jframe in Gridview Jtable
Displaying search results in same panel of gridview in same jframe window.
("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql...Displaying search results in same panel of gridview in same jframe window... search and see the results in the same panel of the Jframe in Gridview Jtable
Could not establish the connection to oracle - JDBC
to use: Connection conn = DriverManager.getConnection("jdbc:oracle:oci8... to use: Connection conn = DriverManager.getConnection ("jdbc:oracle:thin... oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection("jdbc:oracle
JDBC Training, Learn JDBC yourself
JDBC Connection Pooling Accessing Database using Java and JDBC Learn how... you brief description of JDBC Steps for making connection with the database... and database by using connection interface and JDBC driver.   JDBC

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.