Package java.sql

Examples of java.sql.PreparedStatement


            case 1:
            case 2:
                sql = "delete from test";
                break;
            }
            final PreparedStatement prep = conn.prepareStatement(sql);
            Task t = new Task() {
                public void call() throws SQLException {
                    while (!conn.isClosed()) {
                        switch (x % 6) {
                        case 0:
                            prep.executeQuery();
                            break;
                        case 1:
                            prep.execute();
                            break;
                        case 2:
                            prep.executeUpdate();
                            break;
                        case 3:
                            stat.executeQuery("select 1");
                            break;
                        case 4:
View Full Code Here


    public void test() throws SQLException {
        deleteDb("autoRecompile");
        Connection conn = getConnection("autoRecompile");
        Statement stat = conn.createStatement();
        stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY)");
        PreparedStatement prep = conn.prepareStatement("SELECT * FROM TEST");
        assertEquals(1, prep.executeQuery().getMetaData().getColumnCount());
        stat.execute("ALTER TABLE TEST ADD COLUMN NAME VARCHAR(255)");
        assertEquals(2, prep.executeQuery().getMetaData().getColumnCount());
        stat.execute("DROP TABLE TEST");
        stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, X INT, Y INT)");
        assertEquals(3, prep.executeQuery().getMetaData().getColumnCount());
        // TODO test auto-recompile with insert..select, views and so on

        prep = conn.prepareStatement("INSERT INTO TEST VALUES(1, 2, 3)");
        stat.execute("ALTER TABLE TEST ADD COLUMN Z INT");
        assertThrows(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH, prep).execute();
View Full Code Here

    String project = ifile.getProject().getName();
    String insertpath = ifile.getParent().getProjectRelativePath().toString();
    String medium = WGADesignStructureHelper.determineMediaKey(ifile);
    //insertpath = insertpath.substring(0, insertpath.indexOf(ifile.getName()));

    PreparedStatement st = _conn.prepareStatement(expression);
    st.setString(1, filetype);
    st.setString(2, medium);
    st.setString(3, insertpath);
    st.setString(4, file);
    st.setString(5, project);

    st.executeUpdate();

    st.close();
  }
View Full Code Here

    IContainer design = new WGADesignStructureHelper(file).getDesignRoot();
    if (design != null) {

      String expression = "SELECT * FROM references WHERE Project = ? AND FileType = ? AND Medium = ? AND Path Like ?";
      PreparedStatement st = null;
      ResultSet rs = null;
      try {
        st = _conn.prepareStatement(expression);
        st.setString(1, file.getProject().getName());
        st.setString(2, "tml");
        st.setString(3, medium);
        st.setString(4, design.getProjectRelativePath() + "/tml/%");

        rs = st.executeQuery();

        while (rs.next()) {
          String resource = rs.getString("Path");
          if (!resource.endsWith("/")) {
            resource += "/";
View Full Code Here

        org.h2.Driver.load();
        String url = "jdbc:h2:" + getBaseDir() + "/toolsConvertTraceFile";
        Connection conn = DriverManager.getConnection(url + ";TRACE_LEVEL_FILE=3", "sa", "sa");
        Statement stat = conn.createStatement();
        stat.execute("create table test(id int primary key, name varchar, amount decimal)");
        PreparedStatement prep = conn.prepareStatement("insert into test values(?, ?, ?)");
        prep.setInt(1, 1);
        prep.setString(2, "Hello \\'Joe\n\\'");
        prep.setBigDecimal(3, new BigDecimal("10.20"));
        prep.executeUpdate();
        stat.execute("create table test2(id int primary key,\n" +
                "a real, b double, c bigint,\n" +
                "d smallint, e boolean, f binary, g date, h time, i timestamp)", Statement.NO_GENERATED_KEYS);
        prep = conn.prepareStatement("insert into test2 values(1, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        prep.setFloat(1, Float.MIN_VALUE);
        prep.setDouble(2, Double.MIN_VALUE);
        prep.setLong(3, Long.MIN_VALUE);
        prep.setShort(4, Short.MIN_VALUE);
        prep.setBoolean(5, false);
        prep.setBytes(6, new byte[] { (byte) 10, (byte) 20 });
        prep.setDate(7, java.sql.Date.valueOf("2007-12-31"));
        prep.setTime(8, java.sql.Time.valueOf("23:59:59"));
        prep.setTimestamp(9, java.sql.Timestamp.valueOf("2007-12-31 23:59:59"));
        prep.executeUpdate();
        conn.close();

        ConvertTraceFile.main("-traceFile", getBaseDir() + "/toolsConvertTraceFile.trace.db",
                "-javaClass", getBaseDir() + "/Test",
                "-script", getBaseDir() + "/test.sql");
View Full Code Here

    IProject project = file.getProject();
    Set<String> resources = new HashSet<String>();
    IContainer design = new WGADesignStructureHelper(file).getDesignRoot();
    String expression = "SELECT distinct Medium FROM references WHERE Project = ? AND Path Like ?";
   
    PreparedStatement st = null;
    ResultSet rs = null;
    try {
      st = _conn.prepareStatement(expression);
      st.setString(1, project.getName());
      st.setString(2, "designs/" + design.getName() + "/tml/%");

      rs = st.executeQuery();

      while (rs.next()) {
        if (!rs.getString("Medium").equals("") && !rs.getString("Medium").startsWith(".")) {
          resources.add(rs.getString("Medium"));
        }
View Full Code Here

  }

  public Set<String> getScriptPaths(IContainer designRoot, String scriptType) {
    Set<String> resources = new HashSet<String>();
    IProject project = designRoot.getProject();
    PreparedStatement st = null;
    ResultSet rs = null;
    try {     
      String expression = "SELECT Path, File FROM references WHERE Project = ? AND FileType = ? AND Path Like ?";
      st = _conn.prepareStatement(expression);
      st.setString(1, project.getName());
      st.setString(2, scriptType);
     
     
      designRoot.getProjectRelativePath().append("scripts").append(scriptType);
     
      st.setString(3, designRoot.getProjectRelativePath().append("scripts").append(scriptType).toString() + "%");
 
      rs = st.executeQuery();
 
      while (rs.next()) {
        String resource = rs.getString("Path");
        if (!resource.endsWith("/")) {
          resource += "/";
View Full Code Here

        String url = "jdbc:h2:" + getBaseDir() + "/utils";
        String user = "sa", password = "abc";
        String fileName = getBaseDir() + "/b2.sql";
        Connection conn = DriverManager.getConnection(url, user, password);
        conn.createStatement().execute("CREATE TABLE TEST(ID INT PRIMARY KEY, BDATA BLOB, CDATA CLOB)");
        PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?, ?)");

        prep.setInt(1, 1);
        prep.setNull(2, Types.BLOB);
        prep.setNull(3, Types.CLOB);
        prep.execute();

        prep.setInt(1, 2);
        prep.setString(2, "face");
        prep.setString(3, "face");
        prep.execute();

        Random random = new Random(1);
        prep.setInt(1, 3);
        byte[] large = new byte[getSize(10 * 1024, 100 * 1024)];
        random.nextBytes(large);
        prep.setBytes(2, large);
        String largeText = new String(large, "ISO-8859-1");
        prep.setString(3, largeText);
        prep.execute();

        for (int i = 0; i < 2; i++) {
            ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST ORDER BY ID");
            rs.next();
            assertEquals(1, rs.getInt(1));
View Full Code Here

            println("seed: " + seed);
            Random random = new Random(seed);
            ArrayList<String> params = New.arrayList();
            String condition = getRandomCondition(random, params, columns, compares, values);
            //   System.out.println(condition + " " + params);
            PreparedStatement prep0 = conn.prepareStatement(
                    "select * from test0 where " + condition
                    + " order by 1, 2, 3");
            PreparedStatement prep1 = conn.prepareStatement(
                    "select * from test1 where " + condition
                    + " order by 1, 2, 3");
            for (int j = 0; j < params.size(); j++) {
                prep0.setString(j + 1, params.get(j));
                prep1.setString(j + 1, params.get(j));
            }
            ResultSet rs0 = prep0.executeQuery();
            ResultSet rs1 = prep1.executeQuery();
            assertEquals("seed: " + seed + " " + condition, rs0, rs1);
            if (params.size() > 0) {
                for (int j = 0; j < params.size(); j++) {
                    String value = values[random.nextInt(values.length - 2)];
                    params.set(j, value);
                    prep0.setString(j + 1, value);
                    prep1.setString(j + 1, value);
                }
                assertEquals("seed: " + seed + " " + condition, rs0, rs1);
            }
        }
        db.execute("drop table test0, test1");
View Full Code Here

                boolean result;
                if (params == null || params.length == 0) {
                    stat = conn.createStatement();
                    result = stat.execute(sql);
                } else {
                    PreparedStatement prep = conn.prepareStatement(sql);
                    stat = prep;
                    for (int j = 0; j < params.length; j++) {
                        prep.setObject(j + 1, params[j]);
                    }
                    result = prep.execute();
                }
                if (result) {
                    ResultSet rs = stat.getResultSet();
                    s = "rs: " + readResult(rs);
                } else {
View Full Code Here

TOP

Related Classes of java.sql.PreparedStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.