zoukankan      html  css  js  c++  java
  • MySQL新建表

    package MySQLExercise;

    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;

    public class ExerciseSecond {
    public static final String DBDRIVER="com.mysql.jdbc.Driver";
    public static final String DBURL="jdbc:mysql://127.0.0.1:3306/javademo";
    public static final String DBUSER="root";
    public static final String DBPASS="123";
    public static void main(String args[])throws Exception {
    Connection conn = null;
    Statement stmt = null;
    BufferedReader buff=new BufferedReader(new InputStreamReader(System.in));
    String str=null;
    StringBuffer sql=new StringBuffer();
    sql.append("create table ");

    System.out.print("Please input table name : ");
    str=buff.readLine();
    sql.append(str);
    sql.append("(");
    System.out.println("Please input field,press Enter to end: ");
    while(true){
    System.out.print("Please input filed name : ");
    str=buff.readLine();
    if("".equals(str)) break;
    sql.append(str);
    }
    sql.append(",");
    int len=sql.length();
    sql.delete(len-1,len);
    sql.append(")");

    System.out.println(sql);

    Class.forName(DBDRIVER);
    conn= DriverManager.getConnection(DBURL,DBUSER,DBPASS);
    stmt=conn.createStatement();
    stmt.execute(sql+"");
    System.out.println("New table created.");
    }

    }
  • 相关阅读:
    mysql导sql脚本
    oracle导sql脚本
    基于jdk proxy的动态代理模式
    vue组件之组件的生命周期
    vue组件之组件间的通信
    python-爬虫scrapy框架安装及基本使用
    mongdb的使用
    python-爬虫 多线程爬虫
    python-爬虫 爬虫利器BeautifulSoup
    python-爬虫lxml库
  • 原文地址:https://www.cnblogs.com/ssMellon/p/6508113.html
Copyright © 2011-2022 走看看