[英]org.postgresql.util.PSQLException: The server requested SCRAM-based authentication, but no password was provided
import java.sql.*;
import java.io.*;
public class prog1 {
public static void main(String args[]) {
String dbname = "BD22";
String dbuser = "postgres";
String password = "12345";
String url = "jdbc:postgresql://localhost:5432/" + dbname;
try {
BufferedReader in;
in = new BufferedReader( new InputStreamReader( System.in ));
System.out.println("Insira um novo passageiro");
System.out.print(">> Nome: "); String nomePassageiro = in.readLine();
System.out.print(">> Morada: "); String destinopretendido = in.readLine();
System.out.println("Nome: " + nomePassageiro + " Morada: " + destinopretendido);
Connection c = DriverManager.getConnection(url);
c.setAutoCommit(false);
Statement stmt = c.createStatement();
String sql = "INSERT INTO passageiros(nomeP,destinopretendido) VALUES ('" +
nomePassageiro + "','" + destinopretendido + "');";
stmt.executeUpdate(sql);
stmt.close();
c.commit();
c.close();
System.out.println("Estudio " + nomePassageiro + " inserido.");
}
catch (Exception e) {
System.err.println( e.getClass().getName()+": "+ e.getMessage() );
System.exit(0);
}
}
}
When I start the code I can write everything, but when the program starts the "phase" in which it should add to the database what was written, the title error appears and when I debug it, it appears: Disconnected from the target VM, address: '127.0.0.1:54160', transport: 'socket' Someone can help me?当我开始编写代码时,我可以编写所有内容,但是当程序开始“阶段”时,它应该将写入的内容添加到数据库中,出现标题错误,当我调试它时,它出现:与目标 VM 断开连接,地址:'127.0.0.1:54160',传输:'socket' 有人可以帮我吗?
I solved the problem by putting on line 18 (which had the command- Connection c = DriverManager.getConnection(url); ) the following command- Connection c = DriverManager.getConnection(url, dbuser, password);我通过在第 18 行(具有命令 - Connection c = DriverManager.getConnection(url); )下面的命令 - Connection c = DriverManager.getConnection(url, dbuser, password); 解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.