Java jdbc中的更新查询给出运行时错误

时间:2018-08-07 05:42:03

标签: java jdbc

这是一个用于使用更新表并成功编译的程序。

但是在运行时会出错。

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class UpdateProfile {

    public static void main(String args[]) {

        String fname = "ranjesh";
        String lname = "singh";
        String phone = "9870899645";
        String address = "ghz";
        String email = "sarwesh1206@gmail.com";

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/XE", "system", "oracle");

            //system is username and oracle is password
            //userinfo is name of table.

            String query = "UPDATE userinfo set fname = ? ,lname=?,mobile=?,address=? where email = ? ";
            PreparedStatement pstmt = con.prepareStatement(query);

            pstmt.setString(1, fname); // set input parameter 1
            pstmt.setString(2, lname);
            pstmt.setString(3, phone);
            pstmt.setString(4, address);
            pstmt.setString(5, email);

            // set input parameter 2

            pstmt.executeUpdate(); // execute update statement
            con.commit();
            con.close();
            System.out.print("success");

        } catch (Exception ex) {
            System.out.print("error occurred");
        }
    }
}

表userinfo的架构:

schema of table userinfo

0 个答案:

没有答案