String sql = "select * from PJXXMX where PJLX="+lx+" and SFYLYR="+sfy+" "; 
PJLX和SFYLYR是什么数据类型的字段阿字符类型:String sql = "select * from PJXXMX where PJLX='"+lx+"' and SFYLYR='"+sfy+"' ";数字类型:String sql = "select * from PJXXMX where PJLX="+lx+" and SFYLYR="+sfy+" ";  

解决方案 »

  1.   

    你要得到什么数据?
    我晕死了,jsp有你写的这么乱七八糟的么?简直糟蹋了java的优势啊!
      

  2.   


    //MySqlLib.java文件
    import java.sql.*;
    public class MySqlLib 
    {
    private String driver="com.mysql.jdbc.Driver";//自己修改(最好从xml配置文件读取)
    private String url="jdbc:mysql://localhost/test";//自己修改(最好从xml配置文件读取)
    private String user="root";//自己修改(最好从xml配置文件读取)
    private String password="root";//自己修改(最好从xml配置文件读取)
    //private ConnSource dbSource=null;
    private Connection conn=null;
    private Statement stmt=null;
    private CallableStatement callsta=null;//调用存储过程的时候需要
    //构造函数里初始化dbSource
    public MySqlLib()
    {
    //this.dbSource = ConnString.getConnSource();
    }
    //初始化conn
    private void createConn()
    {
    try
    {
    Class.forName(this.driver).newInstance();
    this.conn=DriverManager.getConnection(this.url,this.user,this.password);
    }
    catch(Exception e){ System.out.println(e.toString());}
    //return con;
    }
    //初始化stmt
    private void createStmt() throws Exception
    {
    if(this.conn==null || this.conn.isClosed())
    this.createConn();
    this.stmt = this.conn.createStatement();
    //this.conn.createStatement();
    }
    //
    public CallableStatement createCallsta(String st) throws Exception
    {
    if(this.conn==null || this.conn.isClosed())
    this.createConn();
    this.callsta=conn.prepareCall(st);
    return this.callsta;
    }
    //执行sql语句,返回ResultSet结果集
    public ResultSet executeQuery(String strSql) throws Exception
    {
    if(this.stmt==null)
    this.createStmt();
    return this.stmt.executeQuery(strSql);
    }
    //执行存储过程,返回ResultSet结果集
    public ResultSet executeProcedure(CallableStatement callStmt) throws Exception
    {
    if(this.conn==null || this.conn.isClosed())
    this.createConn();
    //
    if(callStmt==null) return null;
    //
    if(callStmt.execute())
    return callStmt.getResultSet();
    return null;
    }
    //释放资源
    public void close() throws Exception
    {
    this.closeStmt();this.closeConn();
    }
    //
    public void closeStmt() throws Exception
    {
    if(this.stmt!=null)
    this.stmt.close();
    this.stmt=null;
    }
    //
    public void closeConn() throws Exception
    {
    if(this.conn!=null && !this.conn.isClosed())
    this.conn.close();
    this.conn=null;
    }
    }
    //SqlDb.java文件
    import java.sql.*;
    import java.util.ArrayList;public class SqlDb 
    {
    public ArrayList<String> getKeyword() throws Exception
    {
    MySqlLib lib = new MySqlLib();
    ArrayList<String> arr = new ArrayList<String>();
    ResultSet rs = lib.executeQuery("select * from test order by id asc");
    if(rs!=null)
    {
    while(rs.next())
    {
    arr.add(rs.getString("keyword"));
    }
    rs.close();
    lib.close();
    }
    return arr;
    }
    //使用存储过程的
    public ArrayList<String> getCity() throws Exception
    {
    MySqlLib lib = new MySqlLib();
    ArrayList<String> arr = new ArrayList<String>();
    String st="{call getCity()}";//不需要参数
    //CallableStatement callsta = lib.createCallsta(st);
    //callsta.setInt("num",102);//设置参数
    //callsta.setString("Title","卢楚风");
    ResultSet rs = lib.executeProcedure(lib.createCallsta(st));
    if(rs!=null)
    {
    while(rs.next())
    {
    arr.add(rs.getString("city"));
    }
    rs.close();
    lib.close();
    }
    return arr;
    }
    }
    //给你两个类,你自己参考下...
    //输出数据库里的内容,我直接在ShowMsg.java里输出了,你可以把ShowMsg.java换成任意的web页面,只要条用上面两个类的方法即可
    import java.util.ArrayList;public class ShowMsg  
    {
    private static void cout(String obj)
    {
    System.out.print(obj);
    }
    //
    private static void coutln(String obj)
    {
    System.out.println(obj);
    }
    //
    private static void cout(Object obj)
    {
    System.out.print(obj);
    }
    //
    private static void coutln(Object obj)
    {
    System.out.println(obj);
    }
    //以上几个函数最好在一个工具类里单独定义吧,如果需要的话
    private static void msg() throws Exception
    {
    SqlDb db = new SqlDb();
    ArrayList<String> arr = new ArrayList<String>();
    arr = db.getKeyword();
    for(int i=0;i<arr.size();i++)
    {
    coutln(arr.get(i).toString() + "\n");
    }
    }
    //
    private static void city() throws Exception
    {
    SqlDb db = new SqlDb();
    ArrayList<String> arr = new ArrayList<String>();
    arr = db.getCity();
    for(int i=0;i<arr.size();i++)
    {
    coutln(arr.get(i).toString() + "\n");
    }
    }
    //
    public static void main(String[] args) throws Exception
    {
    msg();//city();
    }
    }