想把用户信息保存到数据库中,不知道为什么就错了,求解
程序代码:
package mysql; import java.sql.*; import java.util.Properties; import org.omg.CORBA.StructMemberHelper; import com.mysql.jdbc.JDBC4CallableStatement; public class IncreasUser { private String PROP_FLIE="mysql.ini"; private String driver; private String url; private String user; private String pass; public void insertData (String userName,String userPass)throws Exception { //使用properties类来加载属性文件 Properties props=new Properties(); props.load(new FileInputStream(PROP_FLIE)); driver=props.getProperty("driver"); url=props.getProperty("url"); user=props.getProperty("user"); pass=props.getProperty("pass"); Class.forName(driver);//加载数据库驱动 try( Connection conn=DriverManager.getConnection(url,user,pass);//获取数据库连接 PreparedStatement pstmt=conn.prepareStatement("insert into imguser (user_name,user_pass) values(?,?)"))//插入用户信息 { pstmt.setObject(2, userName); pstmt.setObject(3,userPass); pstmt.executeUpdate();//更新数据库 pstmt.close();//关闭数据库的连接 } catch (Exception e) { // TODO: handle exception System.out.println(e.getMessage()); } } public static void main(String[] args) throws Exception { IncreasUser iUser=new IncreasUser(); String s1="yang"; String s2="13143344"; iUser.insertData(s1,s2); } }
[ 本帖最后由 qq471402415 于 2015-3-20 14:43 编辑 ]