Jdbc tutorial, jdbc connection, java resultset, java, jdbc driver, java database connectivity, jdbc source code, tutorial, programming,JDBC driver, JDBC example, Jdbc examples!
Sycorax - complete tutorials
Programming Tutorials
" Java provides the industry - software companies and customer alike , an opportunity to create a true open computing environment where software is portable,
and customers benefit from increase competition. "
Java and the Future
December 1, 2008-LEJB 3.1: EJB New and Improved!
The EJB 3.0 specification was a huge improvement from what you were used to in the early versions of EJB. Available as an early draft, EJB 3.1 has many more features and is even easier to use.
December 1, 2008-Should Java Assert that Network I/O Can't Occur on the UI Thread?
Doing network I/O on the user interface (UI) thread is bad. Most developers know that and can tell you why; unfortunately, it's still done.
Register now to recieve special alert and latest technology news!
Select Records
First Create the database .Then create table in the database, we need to insert the values in the database. Here we are going to see, how we can insert values in the MySQL database table. We know that tables store data in rows and column format. After creating a database table, you need to insert the values in it. In this section, we are providing an example with code that provides the facility for inserting the values in MySQL database table.
Step 1: Create a Database name - sycoraxjdbctutorial (if you have already created then ignore it)
Use the following MySQL commands to create a user and database, and MySQL from the command line:
mysql>CREATE DATABASE sycoraxjdbctutorial;
mysql>CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'user';
mysql>GRANT ALL PRIVILEGES ON sycoraxjdbctutorial.* TO dbuser'@'localhost';
step 2: Create a Database Table - student (if you have already created then ignore it)
Use the following MySQL commands to create a table in sycoraxjdbctutorial database
To Enter Into the sycoraxjdbctutorial database use the command -
mysql> use sycoraxjdbctutorial;
mysql> CREATE TABLE STUDENT (ROLLNO VARCHAR(5), NAME VARCHAR(30));
Step 4: Insert Data Into the Table -
use mysql command
mysql>INSERT INTO STUDENT VALUES('2','SycoraxJdbcTutorial');
step 3: Download the MYSQL jdbc driver from http://dev.mysql.com/downloads/connector/j/5.1.html
Step 4: Write the program
Source code of the program: RetrieveData.java
import java.sql.*;
public class RetrieveData{
public static void main(String[] args) {
System.out.println("Listing Data of STUDENT table!");
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "sycoraxjdbctutorial";
String driver = "com.mysql.jdbc.Driver";
String user = "dbuser'";
String pass = "user";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
try{
DatabaseMetaData dbm = con.getMetaData();
String query ="SELECT * FROM STUDENT";
ResultSet rs = con.executeQuery(query);
while (rs.next()){
String rollno = rs.getString("ROLLNO");
String name = rs.getString("NAME");
System.out.println("Roll No:" + rollno +"name :" + name);
con.close();
}
}
catch (SQLException s){
System.out.println("No data in the table");
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
Step 5: Execute the program output will be (output will depends on how many rows is there in database table)
Listing Data of STUDENT table!
Roll No: 2 Name: SycoraxJdbcTutorial
<< Insert Records ||Update Table Using Prepared Statements >>


