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!
Insert 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
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
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 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: InsertDataDB.java
import java.sql.*;
public class InsertDataDB{
public static void main(String[] args) {
System.out.println("Inserting values into Mysql database table!");
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "sycoraxjdbctutorial";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"dbuser","user"); // dbuser is database username, user is password
try{
Statement st = con.createStatement();
int val = st.executeUpdate("INSERT INTO STUDENT VALUES("+1+","+"'Sycorax'"+")");
System.out.println("1 row affected");
}
catch (SQLException s){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
Step 5: Execute the program output will be
Inserting values into Mysql database table!
1 row affected
Step 5: Check in the Database - Use mysql command
mysql> select * from student;
+---------+-------------+ | ROLLNO | NAME | +---------+-------------+ | 1 | Sycorax |
<< Create Table || Select Records >>


