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.");
    }

    }
  • 相关阅读:
    使用redisList的做同步队列处理数据
    java 运行服务异常,进入服务分析工具 arthas
    springboot2 搭建webstock 简单例子
    Lambda 表达式 例子。自己看。
    简易的redis分布式锁 RedisLockUtil
    读书笔记
    Kernel panic
    golang 接口
    golang 方法
    ack oscillate
  • 原文地址:https://www.cnblogs.com/ssMellon/p/6508113.html
Copyright © 2011-2022 走看看