JDBC code to save a data in the database

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









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 save word file in 10g database - SQL
code save word file in 10g database  I am not having any idea to save..., Try the following code: import java.io.*; import java.sql.*; public... = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:3306:test","root", "root
Advertisements
save switch data into database - Java Beginners
save switch data into database  switch(menu) { case 1://add...;  Hi Friend, Try the following code: import java.sql.*; import..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost
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
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
HTML code to servlet to database using jdbc
HTML code to servlet to database using jdbc  pls send me the code related to the title   Hi Friend, Try the following code:ADS...:8080/examples/Data"> <table> <tr><td>Message:</td><
Insert Image into Mysql Database through Simple Java Code
simple java code that how save image into mysql database. Before running this java code you need to create data base and table to save image in same database... Insert Image into Mysql Database through Simple Java Code
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
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
How to read data from txt file and save to database MySql - Java Beginners
How to read data from txt file and save to database MySql  Please help me again ,my problem right know is how to read data from txt file then data save to database from JButton.Please give me a tutorial and source code
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 - RoseIndia.Net In this tutorial you will learn the code to read the data from the MySQL table and understand how to execute the query to get the data from database
JDBC Video tutorial - How to delete Data in a MySQL Database?
JDBC Beginners tutorial for deleting the data into MySQL database... Following code connects to the MySQL database and returns the JDBC Connection... the data into MySQL database using the JDBC driver. Check all JDBC Tutorials
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... Following code connects to the MySQL database and returns the JDBC Connection object
JDBC Tutorial - Writing first JDBC example and running in Eclipse
a JDBC program to insert the data into database.  Download the source code... 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 insert data into MySQL database table?
JDBC Video tutorial example for inserting data into MySQL database JDBC... the data into MySQL database using the JDBC driver.ADS_TO_REPLACE_5 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
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt...."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need help creating a mysql database for this code. code is import java.awt...."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register
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
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
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
JDBC - Java Database Connectivity Tutorial
on the Database up to 4 GB. It is a rich data type of JDBC. A large... data base and table to save image in same database.     ...JDBC - Java Database Connectivity Tutorials   
jdbc code - JDBC
jdbc code  are jdbc code for diferent programs are same or different?please provide me simple jdbc code with example?  Hi Friend, Please visit the following link: http://www.roseindia.net/jdbc/ Here you
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
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
jdbc code - JDBC
jdbc code  Dear Sir, i have created one jsp with two fields 1.username 2.password and i have connected to database when the user had entered the fields there are stored in database upto
Save JRadioButton Text in to database - Java Beginners
Save JRadioButton Text in to database   Hello Sir I have Two JaradioButtons 1)Semwise Course 2)Yearwise Course I want To Save Text from...(); JOptionPane.showMessageDialog(null,"Data is successfully inserted into database."); } catch
How to save data - Swing AWT
How to save data  Hi, I have a problem about how to save data ,but first before data save to dababase, data must view in jLisit or Jtable... save data from jList and Jtable(in jList or jTable data will be many).Thank's
database entry using jdbc
database entry using jdbc  Give me a program to enter records in table using jdbc in java.   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 Insert data into database Thanks
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
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
database connectivity - JDBC
database connectivity  can u ppl pls provide me with database... DSN,then follow these steps: 1. Open Data Sources (Start->Control Panel->Administrative Tool->Data Sources(ODBC) 2. Open User DSN tab 3. Add
database - JDBC
database  hai friend, yes i want to use java database connection in eclipse IDE. Thanks in advance
java database connection - JDBC
the data into the MS Access database and retrieve the data from the database table... =DriverManager.getConnection("jdbc:odbc:access"); pstm=connect.prepareStatement("insert into data...java database connection  sir i want to join my project with MS
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: <
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 + AQUA DATA STUDIO
JDBC + AQUA DATA STUDIO  Hello, i have aqua data studio database. I want to do crud operation in jdbc connection using this databse. can you help me out to do this ?? Thanks
how to save uploaded image in database using javascript
how to save uploaded image in database using javascript  Please can you tell me how to store uploaded image in database using java I'll use the upload code as extArray = new Array(".gif", ".jpg", ".png"); function LimitAttach
Java Code - JDBC
(); JOptionPane.showMessageDialog(null,"Data is inserted into the database...Java Code  How To Connect a java program code(Swing) to shared database of SQL Server 2000 on Local Area Network  Hi Friend, Try
insert and delete data in database
insert and delete data in database  insert and delete data in database from servlets through JDBC   Hi Friend, Please visit the following links:ADS_TO_REPLACE_1 Insert Data Delete Data ThanksADS_TO_REPLACE_2
Database Connection - JDBC
Database Connection  In java How will be connect Database through JDBC?  Hi Friend, Please visit the following link: http://www.roseindia.net/jdbc/jdbc-mysql/MysqlConnect.shtml Thanks
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
java database error - JDBC
the following code to insert the data into MS-Access database: import java.sql.... i want to insert data into database(MS-Access) but dont know how to do...()); pstm.executeUpdate(); label.setText("Data is inserted into MS Access database
SQL database parameters should save at where?
SQL database parameters should save at where?  Hi, Currently... the script will be running for very long time, I like to move the SQL database..., if there is a database changed (hostname, username or password) It should
database connectivity - JDBC
database connectivity  example java code for connecting Mysql database using java  Hi friend, Code for connecting Mysql database using...."); Connection conn = null; String url = "jdbc:mysql://localhost:3306
java code - JDBC
java code  how to store the online form in database using jdbc ND TO RETRIVE the that data   Hi Friend, Try the following code: 1)register.jsp: Registration Form First Name: Last Name

Ads