• JAVA sql语句动态参数问题


    对sql语句设置动态参数

    import java.sql.Connection;
    import java.sql.DatabaseMetaData;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    
    
    public class sqlTest {
        static String url = "jdbc:oscar://192.168.1.208:2004/OSRDB";
        static String username = "SYSDBA";
        static String password = "szoscar55";
        public static void main(String[] args) throws Exception{
            Class.forName("com.oscar.Driver");
            Connection con = DriverManager.getConnection(url, username, password);
            DatabaseMetaData data = con.getMetaData();        
    //        String sql = "select * from SINAWEIBO_500 where USER_ID = ?";
            PreparedStatement st = con.prepareStatement("select * from SINAWEIBO_500 where MESSAGE_TYPE = ?");
            st.setObject(1, "1");        
            ResultSet rs = st.executeQuery();
            while(rs.next()){
                System.out.println(rs.getString(2));
            }
        }
    
    }

    刚开始,写的prepareStatement(sql);

    st.setObject(1,"1")结果报的错是Dynamic parameter must used only in prepare statement,后来把sql语句移到preparestatement中,就运行成功了,我也不清楚为什么把sql语句提出来就不对了

  • 相关阅读:
    网页源码爬取
    Vue模板语法上集
    SSH整合
    P1290 欧几里德的游戏
    P1582 倒水
    P2158 [SDOI2008]仪仗队
    P1338 末日的传说
    P1372 又是毕业季I
    P1865 A % B Problem
    P1031 均分纸牌
  • 原文地址:https://www.cnblogs.com/yuwenfeng/p/3259556.html
Copyright © 2020-2023  润新知