Postgresql pgjdbc ng病态区域:
目前,我正在尝试制作一个模块,该模块将通过Postgres上的触发器监听任何更改。我使用的是pgjdbc ng版本0.8.2,从maven repo central下载JAR并将其添加为项目参考 以下是我使用的代码:Postgresql pgjdbc ng病态区域:,postgresql,pg-jdbc,Postgresql,Pg Jdbc,目前,我正在尝试制作一个模块,该模块将通过Postgres上的触发器监听任何更改。我使用的是pgjdbc ng版本0.8.2,从maven repo central下载JAR并将其添加为项目参考 以下是我使用的代码: public class ListenNotify { // Create the queue that will be shared by the producer and consumer private BlockingQueue queue = new ArrayBlock
public class ListenNotify
{
// Create the queue that will be shared by the producer and consumer
private BlockingQueue queue = new ArrayBlockingQueue(10);
// Database connection
PGConnection connection;
public ListenNotify()
{
// Get database info from environment variables
/*
String DBHost = System.getenv("DBHost");
String DBName = System.getenv("DBName");
String DBUserName = System.getenv("DBUserName");
String DBPassword = System.getenv("DBPassword");
*/
String DBHost = "127.0.0.1";
String DBName = "dbname";
String DBUserName = "postgres";
String DBPassword = "postgres";
// Create the listener callback
PGNotificationListener listener = new PGNotificationListener()
{
@Override
public void notification(int processId, String channelName, String payload)
{
// Add event and payload to the queue
queue.add("/channels/" + channelName + " " + payload);
}
};
try
{
// Create a data source for logging into the db
PGDataSource dataSource = new PGDataSource();
dataSource.setHost(DBHost);
dataSource.setPort(5432);
dataSource.setDatabaseName(DBName);
dataSource.setUser(DBUserName);
dataSource.setPassword(DBPassword);
// Log into the db
connection = (PGConnection) dataSource.getConnection();
// add the callback listener created earlier to the connection
connection.addNotificationListener(listener);
// Tell Postgres to send NOTIFY q_event to our connection and listener
Statement statement = connection.createStatement();
statement.execute("LISTEN q_event");
statement.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
/**
* @return shared queue
*/
public BlockingQueue getQueue()
{
return queue;
}
/**
*
* main entry point
*
* @param args
*/
public static void main(String[] args)
{
// Create a new listener
ListenNotify ln = new ListenNotify();
// Get the shared queue
BlockingQueue queue = ln.getQueue();
// Loop forever pulling messages off the queue
while (true)
{
try
{
// queue blocks until something is placed on it
String msg = queue.take().toString();
// Do something with the event
System.out.println(msg);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
运行时,我遇到异常:
病态地区:印度尼西亚[指数为0]
我读过官方的git,说它应该被固定在某个发行号内
如何应用这些修复
谢谢我知道有点晚了;) 我也有同样的问题,也读到问题解决了。但情况似乎并非如此。 无论如何,问题是在创建postgres数据库时,LC_COLLATE可能设置为Indonesian_Indonesia.1252。当尝试建立连接时,会将此值与java语言环境进行比较。在Java Locales类中,该值可能在您的语言中,因此无法找到条目。但是,要解决这个问题,可以将Java语言环境的默认值设置为英语。这当然不是解决问题的最佳方法,但它是有效的。为了安全起见,我会在连接建立后放回去 您可以按如下方式设置默认值:
Locale.setDefault(Locale.ENGLISH)