JDBC code to save a data in the database

Ads
 

JDBC code to save a data in the database

I need a code to save a data in the database can anyone help?

View Answers

May 9, 2012 at 12:37 PM

The given code set up the connection between java and mysql using JDBC and saves the data into the database.

import java.sql.*;

public class InsertValues{
 public static void main(String[] args) {
 System.out.println("Inserting values in Mysql database table!");
  Connection con = null;
  String url = "jdbc:mysql://localhost:3306/";
  String db = "jdbctutorial";
  String driver = "com.mysql.jdbc.Driver";
  try{
  Class.forName(driver);
  con = DriverManager.getConnection(url+db,"root","root");
  try{
  Statement st = con.createStatement();
  int val = st.executeUpdate("INSERT employee VALUES("+1+","+"'Roseindia'"+")");
  System.out.println("1 row affected");
  }
  catch (SQLException s){
  System.out.println("SQL statement is not executed!");
  }
  }
  catch (Exception e){
  e.printStackTrace();
  }
  }
}

For more information, visit the following link:

JDBC Tutorials

Ads









Related Tutorials/Questions & Answers:
How to save database data into excelsheet using hibernate
How to save database data into excelsheet using hibernate  How to save database data into excelsheet using hibernate
code to establish jdbc database connectivity in jsp
code to establish jdbc database connectivity in jsp  Dear sir, i'm in need of code and procedure to establish jdbc connectivity in jsp
Advertisements
code to establish jdbc database connectivity in jsp
code to establish jdbc database connectivity in jsp  Dear sir, i'm in need of code and procedure to establish jdbc connectivity in jsp
Application reading data from JDBC database
" should read data from from a JDBC database named PrimeGame with TABLE PRIMEGAMETABLE...Application reading data from JDBC database  I would like to develop an online registration system that captures details of potential candidates
export data from database to excel sheet - JDBC
export data from database to excel sheet  I am facing a problem about exporting required data from database table to ms-excel sheet.i mean whenever I... reply for me Thank you!  Hi Friend, Try the following code
JDBC Video tutorial - How to update Data in a MySQL Database?
JDBC Beginners tutorial for updating the data into MySQL database The Java Database Connectivity API (JDBC) provides rich set of classes, interfaces... the example program for updating the data into MySQL database using the JDBC driver
place data in text fields from database using jdbc
place data in text fields from database using jdbc  i want get the data from database and place the records in the respective textfields using jdbc and swing like eno,ename,loc from emp table
JDBC Video tutorial - How to read Data from MySQL Database?
JDBC Beginners tutorial for reading the data from MySQL database... the database. Step 5: Display the data Following code block prints the data... for reading the data from MySQL database using the JDBC driver. Check all
JDBC Tutorial - Writing first JDBC example and running in Eclipse
to insert the data into database.  Download the source code of JDBC Example... to write simple JDBC program to connection to database and then perform insert... jar file to the project, writing the JDBC code and finally executing
JDBC Video tutorial - How to delete Data in a MySQL Database?
JDBC Beginners tutorial for deleting the data into MySQL database... the data from Java program: Step 1: Connect to the MySQL database Following code... Database Connectivity API (JDBC) provides rich set of classes, interfaces
code for selected checkbox columns data from database
code for selected checkbox columns data from database  in my page iam... one or more checkboxes i have to get data of that selected columns only. what is the jsp code for this thanks in advance kalyani
How to Validate JRadioButton and How to Save data from JRadioButton to MS Access Database - Java Beginners
How to Validate JRadioButton and How to Save data from JRadioButton to MS... JRadioButton I want Store Information from JRadioButton to MS Access Database, and I want Select any One JRadioButton At a Time out of Two. plz Give Me Code Sir
JDBC Video Tutorial- How to insert data into MySQL database table?
JDBC Video tutorial example for inserting data into MySQL database JDBC... for inserting the data into MySQL database using the JDBC driver. Download... and in this video I have explained the steps of write code to insert the data
jsp code for display of data from database and snap shot of the output
jsp code for display of data from database and snap shot of the output  i am using JSP.i want to insert data into database and also want to display the things i have entered in the same page inside the corresponding fields
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
To save table format data in pdf/excel in jsp
To save table format data in pdf/excel in jsp  Hello, I am doing web application project in jsp. In webform ,I am displaying database data in html table. So my question is ,I want so save this html format data in pdf/excel format
how to make a radiobutton selected when retrieving data from database using struts framework and spring jdbc
how to make a radiobutton selected when retrieving data from database using struts framework and spring jdbc  how to make a radio button selected when retrieving data from database using struts framework and spring jdbc
The code for retrieving data from database into Drop Down List.
The code for retrieving data from database into Drop Down List.  <% DataSource data = new MysqlDataSource(); Connection con...;% } %> // my code for displaying quantity is below
save data DAO
save data DAO  how to save data in db   package com.tcs.ignite.dao; import com.tcs.ignite.bean.User; import com.tcs.ignite.connection.Connectiondetails; import java.sql.ResultSet; import java.sql.SQLException; import
jdbc code
jdbc code   import java.sql.*; import java.io.*; import java.util.*; public class CallBill { public static void main(String args[])throws... oracle.jdbc.driver.OracleDriver()); Connection con=DriverManager.getConnection("jdbc:oracle:thin
how to show data in database ?
how to show data in database ?  how to show the data in the database to the user in the textbox so that user can modify it and save it again
image retrive into DataBase - JDBC
the image into DataBase. Thanks & Regards, VijayaBabu.M  Hi, Retrieving image from database is easy task. JDBC provides all the necessary API and function to retrieve the image from database. You retrieve image from database
Save a pdf with spring as below code
Save a pdf with spring as below code   c:/report.pdf All work in the same way, but never save the report to disk. How to solve this problem? please reply me
Working with Database through JDBC
to work with database. For this you can write JDBC code in the action method...Working with Database through JDBC   ... method will contain the jdbc code to check whether the user name and password
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
JDBC
JDBC code to save a data in the database  I need a code to save a data in the database can anyone help?   The given code set up the connection between java and mysql using JDBC and saves the data into the database
JDBC
JDBC save a data in the database  I need a code to save a data in the database can anyone help?   The given code set up the connection between java and mysql using JDBC and saves the data into the database. import
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database.... Apache Tomcat/6.0.29  We have used MySQl database. 1)page.jsp: <
How can we save a data list in jsf?
How can we save a data list in jsf?  I have a code in jsf that fires a query in Data Base each time it is called, i have added a validation check... it is called again. I tried using save State but it did not help as other functions got
how to import excel sheet into mysql database and save it as a table in database
how to import excel sheet into mysql database and save it as a table in database  sir, i want to import an excel sheet into a MySQL database and after importing it i want to store the excel sheet as a table in database

Ads