SQL数据库连接参数设置如何打开
答案:2 悬赏:0 手机版
解决时间 2021-02-09 23:48
- 提问者网友:爱了却不能说
- 2021-02-09 08:57
SQL数据库连接参数设置如何打开
最佳答案
- 五星知识达人网友:不想翻身的咸鱼
- 2021-02-09 09:50
private Connection conn = null;
private PreparedStatement pstmt = null;
private ResultSet rs = null;
try {
String sql = "INSERT INTO \"UserInfo\" (\"MESSAGE\") VALUES (?);";
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(dbURL, userName, password);
pstmt = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
pstmt.setString(1, msg);
pstmt.execute();
rs = pstmt.getGeneratedKeys();
if (rs.next()) {
userID = rs.getObject(1).toString();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
是要这个吗?
private PreparedStatement pstmt = null;
private ResultSet rs = null;
try {
String sql = "INSERT INTO \"UserInfo\" (\"MESSAGE\") VALUES (?);";
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(dbURL, userName, password);
pstmt = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
pstmt.setString(1, msg);
pstmt.execute();
rs = pstmt.getGeneratedKeys();
if (rs.next()) {
userID = rs.getObject(1).toString();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
是要这个吗?
全部回答
- 1楼网友:猎心人
- 2021-02-09 10:45
看看防火墙设置 1433端口开了没
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯