Copy One Database Table to Another : Table « Database SQL JDBC « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Database SQL JDBC » Table 




Copy One Database Table to Another
   

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Main {
  public static void main(String[] argvthrows Exception {
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "jdbcMysql";
    String userName = "root";
    String password = "root";

    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection conn = DriverManager.getConnection(url + dbName, userName, password);
    Statement st = conn.createStatement();
    int rows = st.executeUpdate("INSERT INTO myTable SELECT * FROM jdbc4.Copyemployee");
    if (rows == 0) {
      System.out.println("Don't add any row!");
    else {
      System.out.println(rows + " row(s)affected.");
      conn.close();
    }
  }
}

   
    
    
  














Related examples in the same category
1.Table exist?
2.List tables in a database
3.Listing All Table Names in a Database
4.Get all table schemas
5.Get all table catalogs
6.Another Method To Check Table Existance
7.Get Catalog Name From ResultSet Metadata
8.Get Available Table Name In A Database
9.Get Table Or View Name From A Database
10.Database metadata: data type
11.Deleting a Table from Database
12.Retrieving Tables from a Database
13.List the Tables in an SQL database
14.Create table with primary key
15.Create table with foreign key
16.Create data table 3
17.Create supplier table
18.Create data table: reference
19.Create data table 2
20.Creating a Database Table called my_table with one column, col_string, which holds strings.
21.Deleting a Database Table called my_table from a database.
22.Getting Rows from a Database Table
23.Getting the Number of Rows in a Database Table
24.Inserting a Row into a Database Table Using a Prepared Statement
25.Inserting a Row into a Database Table
26.Updating a Row in a Database Table
27.Deleting a Row from a Database Table
28.Deleting All Rows from a Database Table
29.Create data type and data table
30.Table and column existance
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.