Skip to main content
gamedev.net
🔒 Locked

[java] inserting a row in a table (SOLVED)

Started by cignox1 0 replies 700+ views
Original Post
cignox1
cignox1
I'm creating a simple interface for a mysql database, and I need to create interactively a table. I do as follows, and it seems to work:

        String cmd = "create table "+name+" (";

        try
        {
            ResultSetMetaData meta = data.getMetaData();
            for(int i = 1; i <= meta.getColumnCount(); i++)
            {
                if(i > 1) cmd = cmd+",";
                cmd = cmd+" "+meta.getColumnName(i)+" "+meta.getColumnTypeName(i)+"";
                if(meta.getColumnClassName(i).compareTo("java.sql.Date") == 0 ||
                        meta.getColumnClassName(i).compareTo("java.sql.Time") == 0) continue;
                cmd = cmd+"("+meta.getColumnDisplaySize(i)+")";
            }
            cmd = cmd+" )";
            executeQuery(cmd);


Just after that, I try to fill it with new rows:

            Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
            ResultSet newt = stat.executeQuery("select * from "+name);
            System.out.println(name);
            newt.moveToInsertRow();


but at newt.moveToInsertRow(); it throwns an exception, with the following message: Result Set not updatable.This result set must come from a statement that was created with a result set type of ResultSet.CONCUR_UPDATABLE, the query must select only one table, and must select all primary keys from that table. See the JDBC 2.1 API Specification, section 5.6 for more details. Where is the problem? [Edited by - cignox1 on October 14, 2005 7:41:50 PM]
cignox1
cignox1
Ah, ok, it seems that in order to work, there must be at least a primary key specified and all the primary key should be selected.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.