Home Answers Viewqa Java-Beginners java plus database

 
 


Anita Thapa
java plus database
3 Answer(s)      4 years and 6 months ago
Posted in : Java Beginners

View Answers

November 17, 2008 at 11:52 PM


Hi friend,

Code to solve the problem :

database table "city"

CREATE TABLE `city` (
`id` bigint(20) default NULL,
`city` varchar(150) default NULL,
`zip` bigint(20) default NULL,
`sport_id` bigint(20) default NULL,
`sport_name` varchar(150) default NULL
)

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"));




}
}

November 17, 2008 at 11:56 PM


For more information on JDBC MySql visit to :

http://roseindia.net/jdbc/

Thanks









Related Pages:
java plus database - Java Beginners
java 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
the relational database(DML,DCL,DDL). SQL*PLUS commands are used to format query...SQL Plus  What is SQL Plus?   Hi, Here is the answer, SQL*PLUS is a command line tool where as SQL and PL/SQL language interface
deletion in b plus tree
deletion in b plus tree  please help me out!! i need a code for deletion on b-plus tree in JAVA. its urgent please help
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
Java bigdecimal plus method example
Java bigdecimal plus method example   ...); Java_bigdecimal_plus_example.java...; import java.math.RoundingMode; public class Java_bigdecimal_plus
database
database  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
DATABASE
DATABASE  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
Database
Database  How to represent data from database in a tree?   Please visit the following link: Retrieve data from database in tree using Java Swing
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
Database
Database  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
database
database  Im doing my project in java swings...netbeans I wanted java source code to establish connection to postgresql_8.1 using jdbc and create a user defined database and a table in that database and insert values Plz help me
database
database  Can you please help me to establish database connection to ms sql 2000 from java swing in netbeans
database
database..im doing my project in java swings.....netbeans Kindly help me ThankYou...database  I want to let the user select one of the database type... give the name of the database name that he want to create in a textfield
database
of combo box in java - from database? you had given me the answer <%@page...database  How can i get combo box values from database?? or how... name officename and database name jsw   <%@page import="java.sql.
database
database  i am created one table in mysql database with one of the column name is emailid.now i want to write a java code that if the mail id... or not. If it is already exist in database, then show a message 'Already exists
Database drivers - JDBC
Database drivers  Please give me types of drivers and explain them... as: * JDBC-ODBC bridge plus ODBC driver, also called Type 1. * Native-API, partly Java driver, also called Type 2. * JDBC-Net
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
Importing data into sql plus from a text file...
Importing data into sql plus from a text file...  How to import a text file into oracle 10g enterprise edition directly to create tables and data
java database
java 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,Java
Database,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 database
java 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
Accept command in Oracle
is retrieved from database. You can use SQL Plus to generate many types...Accept command in Oracle In this section we will see how to use the Accept command in SQL Plus. The ACCEPT command in SQL Plus is used to take the input from
JAVA DATABASE CONNECTION WITH JTABLE
JAVA DATABASE CONNECTION WITH JTABLE  HOw To Load Database Contents From Access Database to JTable without using Vector
Map java Object to database.
Map java Object to database.  How do you map Java Objects with Database tables
Database programming - Java Beginners
Database programming  How to do a Database programing with Balanced Multiway Tree(B+ Tree,not Binary Tree) in java
database connectivity
database connectivity  describe java program steps in order to get connectivity to database along with example
database - JDBC
database  hai friend, yes i want to use java database connection in eclipse IDE. Thanks in advance
image in database
image in database  how to set image in database and retrieve it using servlet(java)in msaccess
DataBase Connection
DataBase Connection  How to connect java and Oracle 10g? Tell me Jdbc connection
Excel to database
Excel to database  Hi I want to update SQL database with the values from excel using java code. Can you help me
java and database - Java Beginners
java and database  code to read a csv file  Hi Friend, We have used POI Library to read the csv file in java: import java.io.*; import org.apache.poi.hpsf.*; import org.apache.poi.hssf.usermodel.*; import
jsp database
jsp database   I want to retrive value in my jsp page but i dont want show my database query in my jsp page. is there any other method to show value in my jsp page using java class
Database - Java Beginners
Database  How to do database connection when using weblogic server? Any specific condition or difference
innerclass and database - Java Beginners
innerclass and database  program using innerclass to implement numerical bisection operation to call a procedure to store and update data in a database
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
Connection to database - Java Beginners
on a Project on Jsp We hve some JSP Pages & trying to connect to our Database . We are using SQL server 2000 ? We are not able to connect our database Tables.../connect_jsp_with_mysql.shtml Because, we didn't use sql server 2000 database
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
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... i was using this code.... try { Driver d=(Driver)Class.forName
java database connection - Struts
java database connection  how to connect a database in struts program?  First Add two jar file1> commons-dbcp-1.2.x.jar2> mysql...; value="jdbc:mysql:///database_name?autoReconnect=true"
java database error - JDBC
java database error  hi all i am writing one swing application where i want to insert data into database(MS-Access) but dont know how to do... the following code to insert the data into MS-Access database: import java.sql.
Java database connectivity
Java database connectivity  Hi sir I need a code to create an application where user enter name in text box and that should be stored in database. Plz help me out its very urgent.   import java.sql.*; import java.awt.
excel to database
excel to database   How to export data from excel sheet to mysql database by using java with request parameter Here q=40 is a request parameter ..request parameter using i export the all data to database   <
Connecting to MYSQL Database in Java
Connecting to MYSQL Database in Java  I've tried executing the code... to the database"); conn.close(); System.out.println("Disconnected from database"); } catch (Exception e) { System.out.println("Error
Sum database colum in java
Sum database colum in java  please i have two columns-col1 and col2, col1 contain item and col2 contain the quantity of the item columns... the database to sum the Items and display output so that it will be like
unable to connect database in java
unable to connect database in java  Hello Everyone! i was trying to connect database with my application by using java but i am unable to connect... created. 6) Restart your compiler and compile your java code. For Inserting Data
code for database deadlock sicuation in java
code for database deadlock sicuation in java  how to prepare code for database deadlock situation in java(JDBC
problem in database
problem in database   thanks for web site. I want change this code to insert data into PostgreSql database using jsp,servlets. but i getting...){ out.println("Couldn't load database driver: " + e.getMessage()); } catch

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.