November 17, 2008 at 11:52 PM
"city.java"
import java.io.*;
import java.util.*;
import java.sql.*;
class city
{
public static void main(String[] args) throws Exception
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader bufReader = new BufferedReader(isr);
ArrayList al = new ArrayList();
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:
mysql://localhost:3306/";;
String dbName = "city";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
String option="";
do
{
System.out.println("Enter Options");
System.out.println("a. Enter a number");
System.out.println("b. Stop the program");
option = bufReader.readLine();
if(option.equals("a"))
{
System.out.println("Enter new Number");
Integer number = Integer.parseInt(bufReader.readLine());
//System.out.println("number : " + number);
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
String query = "SELECT count(*) FROM city where id="+number;
int i=0;
do
{
Statement st = conn.createStatement();
//System.out.println("query "+ query);
ResultSet res = st.executeQuery("SELECT count(*) FROM city where id="+number);
while (res.next()) {
i = res.getInt(1);
if(i>0)
{
System.out.println(i+" number already exists");
System.out.println("Enter again new Number");
number = Integer.parseInt(bufReader.readLine());
}
else
{
System.out.println("Enter Zipcode");
Integer zipcode = Integer.parseInt(bufReader.readLine());
//System.out.println("zipcode : " + zipcode);
try
{
Statement st1 = conn.createStatement();
//System.out.println("query "+ query);
ResultSet res1 = st.executeQuery("SELECT * FROM city where zip="+zipcode);
while (res1.next()) {
System.out.println("City : " + res1.getString(2));
System.out.println("Sport id : " + res1.getString(4));
System.out.println("Sport Name : " + res1.getString(5));
}
res1.close();
}
catch(Exception e)
{
}
}
}
//res.close();
}while(i!=0);
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
//e.printStackTrace();
}
}
if(option.equals("b"))
{
System.exit(0);
}
}
while(!option.equals("b"));
}
}
Related Tutorials/Questions & Answers:
java plus database - Java Beginnersjava plus database kathmandu Sports Club
In order to have more.... Module diagram
4.
Java-program
Hi friend,
Code to solve the problem :
database table "city"
CREATE TABLE `city
SQL Plus used to query the relational
database(DML,DCL,DDL). SQL*
PLUS commands are used...SQL Plus What is SQL
Plus?
Hi,
Here is the answer,ADS_TO_REPLACE_1
SQL*
PLUS is a command line tool where as SQL and PL/SQL language
Advertisements
java databasejava database help me with this...i never learn build
java database... to design and implement objects needed for a program that maintains a
database.../teacher information, search it, alter it, etc. The
database is maintained as a list
Database,JavaDatabase,Java help me for the following things
if one customer... me the how to write the query in MySQL
database and i want coding for this one in Java.because i am using
Java as the front end.
1)page.jsp:
<
java and databasejava and database sir
i want to prepare a sign in form and i want to check that user name is exist or not in
database if it is exist in
database then return it is allready exist otherwise it is registered in data base
thank u
Java Database Program Java Database Program Write a program in
Java that connects to a
database and generates a report consisting of the courses in whom the total percentage of number of students failed is more than 80% of the total number
database links:
Connect JSP with
database Mysql
Connect
Java with
database Mysql...database tell me use about
database and give me a small program.
It is secure and can easily be accessed, managed, and updated. Moreover
database links:
Connect JSP with
database Mysql
Connect
Java with
database Mysql...database tell me use about
database and give me a small program.
It is secure and can easily be accessed, managed, and updated. Moreover
database links:
Connect JSP with
database Mysql
Connect
Java with
database Mysql...database tell me use about
database and give me a small program.
It is secure and can easily be accessed, managed, and updated. Moreover
databasedatabase I wanted to know if it is possible to establish
database connection on a remote pc with mysql using
java swings from netbeans and then create a
database on the remote pc....
Kindly help me
DATABASEDATABASE How can i get combo box values from
database??
or how can i get values in the drop down menu of the html which is similar to dat of combo box in
java - from
database DatabaseDatabase How to represent data from
database in a tree?
Please visit the following link:
Retrieve data from
database in tree using
Java Swing
Java bigdecimal plus example
Java bigdecimal
plus example
Example below demonstrates working of bigdecimal class
plus... method return type is
plus of this.object or simply
+this.object.
Scale
DatabaseDatabase from
java code i have to retrieve some data from a
database, which is present in a different timezone.
Scenario :- My
database... in
database timezone is 9PM 15APR2012. I want to retrieve something from
database java database connection - JDBCjava 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
java with Oracle Databasejava with Oracle Database Hello
I have been encountering a problem regarding creating a table with Oracle.When i am creating new table in the
Database using Oracle , it is giving error saying an errror occured incursive sql