the result of the following coding: it only create a table , but not 将 DATA 存入MYSQL database? pls help!!!
how to insert data into MYSQL database after create a table?
*****************************************************************************************************************************
Creating a Mysql Table to Store Java Types!
CREATE TABLE fsmccc(ID int(11) primary key NOT NULL default '0'  , `INPUT_VALUE` int(11) NOT NULL default '0', `CURR_STATE` varchar(1) default NULL, `OUTPUT_VALUE` int(11) NOT NULL default '0')
Table is all ready exists!
*****************************************************************************************************************
package demo.createdb;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement; public class CreateMysqlTable {
public static void main(String[] args) {
int count;
System.out.println("Creating a Mysql Table to Store Java Types!");
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "myfsmdata";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";//made on may27 can input matrix , the fsm_sql02  is final;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db, user, pass);
try{
Statement st = con.createStatement();
String table = "CREATE TABLE fsmccc("+ "ID int(11) primary key NOT NULL default '0'  , "              
                                     + "`INPUT_VALUE` int(11) NOT NULL default '0', "  
                                     + "`CURR_STATE` varchar(1) default NULL, "
                                                                    
             + "`OUTPUT_VALUE` int(11) NOT NULL default '0')";
                                        
st.executeUpdate(table);
System.out.println(table);
count = st.executeUpdate (
               "INSERT INTO fsmccc(id, INPU_VALUE,,CURR_STATE,OUTPUT_VALUE)"
               + " VALUES"
               + "(1,0,0,'A'),"
               + "(2,1,1,'B'),"
               + "(3,0,1,'B'),"
               + "(4,1,1,'C'),"
               + "(5,0,0,'C'),"
               + "(6,0,0,'C')");
con.close();
System.out.println (count + " rows were inserted");
}
catch (SQLException s){
System.out.println("Table is all ready exists!");
}
}
catch (Exception e){
e.printStackTrace();
}

}
}

解决方案 »

  1.   

    count = st.executeUpdate ( 
                  "INSERT INTO fsmccc(id, INPU_VALUE,,CURR_STATE,OUTPUT_VALUE)" ....
    这个中间有两个逗号.是不是笔误啊!这条sql 比较复杂最好先把它输出来 看在 sql里面可以执行不.
      

  2.   

    INSERT INTO fsmccc(id, INPU_VALUE,,CURR_STATE,OUTPUT_VALUE)  VALUES (1,0,0,'A')
    INSERT INTO fsmccc(id, INPU_VALUE,,CURR_STATE,OUTPUT_VALUE)  VALUES (2,1,1,'B')
    INSERT INTO fsmccc(id, INPU_VALUE,,CURR_STATE,OUTPUT_VALUE)  VALUES (3,0,1,'B')
    ...
      

  3.   

    sorry, 是笔误啊!Thank. but even without 两个逗号, 1 个逗号 it does not work!
    but I use mysql script to run it works. but I want java work on it!
    **************mysql script*********************
    insert into fsmccc values
     (1,0,0,"A"), 
     (2,1,1,"B"),
     (3,0,1,"B"),
     (4,1,1,"C"),
     (5,0,0,"C"),
     (6,1,0,"A");
      

  4.   

    Thank WWWWb, now I try to use your method!
      

  5.   

    这样试试
    count = st.executeUpdate (
                  "INSERT INTO fsmccc(id, INPU_VALUE,,CURR_STATE,OUTPUT_VALUE)"
                  + " VALUES"
                  + "(1,0,0,'A'),"
                  + "(2,1,1,'B'),"
                  + "(3,0,1,'B'),"
                  + "(4,1,1,'C'),"
                  + "(5,0,0,'C'),"
                  + "(6,0,0,'C');"); 
      

  6.   

    int count = st.executeUpdate ("INSERT INTO fsmccc(id, INPUT_VALUE,CURR_STATE,OUTPUT_VALUE) VALUES (1,0,0,'A'),"+   
    "INSERT INTO fsmccc(id, INPUT_VALUE,CURR_STATE,OUTPUT_VALUE)VALUES(3,0,1,'B'),"+
                  
     "INSERT INTO fsmccc(id, INPUT_VALUE,CURR_STATE,OUTPUT_VALUE)VALUES(4,1,1,'C'),"+
                   
     "INSERT INTO fsmccc(id, INPUT_VALUE,CURR_STATE,OUTPUT_VALUE)VALUES(5,0,0,'C'),"+
                   
    "INSERT INTO fsmccc(id, INPUT_VALUE,CURR_STATE,OUTPUT_VALUE)VALUES(6,0,0,'C')");Thank you for your suggestion!!!
      

  7.   

    Hi,wwwwb:
    the same result like this :
    Creating a Mysql Table to Store Java Types! 
    CREATE TABLE fsmccc(ID int(11) primary key NOT NULL default '0'  , `INPUT_VALUE` int(11) NOT NULL default '0', `CURR_STATE` varchar(1) default NULL, `OUTPUT_VALUE` int(11) NOT NULL default '0') 
    Table is all ready exists! it means that it only create a table , but never insert data into the table!
    I only can write a scrpit to insert the data into the table, but use Java I have the trouble to do it!Thank you for your response!