那就奇怪了
package JDBC;
import java.io.IOException;
import java.sql.*;
public class MysqlData {
public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException {
String i="111";
Connection con=ConnectionFactory.getConnect();
try{
PreparedStatement stmt = con.prepareStatement("select item_id from item where item_id=?");
stmt.setString(0,"002");
ResultSet rs = stmt.executeQuery();
while(rs.next()) {
i=rs.getString("item_id");
System.out.println(i);
}
rs.close();
stmt.close();
}catch(Exception e){
}finally{
con.close();
}
}
为什么我这个打印不出东西来啊 我的数据库里有记录啊
工厂类:
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;
public class ConnectionFactory {
static Properties pr;
static Connection con=null;
static String dir=null;
static String url1=null;
static String user=null;
static String ps=null;
public static void initParams(String paramFileLocaltion) throws IOException{
FileInputStream fi=new FileInputStream(paramFileLocaltion);
pr= new Properties();
pr.load(fi);
dir=pr.getProperty("Dir");
url1=pr.getProperty("url");
user=pr.getProperty("user");
ps=pr.getProperty("ps");
}
public static Connection getConnect() throws ClassNotFoundException, SQLException, IOException{
if(con==null||con.isClosed()){
ConnectionFactory.initParams("F:\\JAVA\\HomeWork\\src\\parm.txt");
Class.forName(dir);
con=DriverManager.getConnection(url1,user,ps);
}
return con;
}
}