HY,
我有以下代码:
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.*;
/
public class RegexSimple4
{
public static void main(String[] args) {
try {
Scanner myfis = new Scanner(new File("D:\\myfis32.txt"));
ArrayList <String> foundaz = new ArrayList<String>();
ArrayList <String> noduplicates = new ArrayList<String>();
while(myfis.hasNext()) {
String line = myfis.nextLine();
String delim = " ";
String [] words = line.split(delim);
for (String s : words) {
if (!s.isEmpty() && s != null) {
Pattern pi = Pattern.compile("[aA-zZ]*");
Matcher ma = pi.matcher(s);
if (ma.find()) …
Run Code Online (Sandbox Code Playgroud) 我有一个Heroku PostgreSQL数据库,我无法从Java连接.我尝试了不同的方法但没有成功.
下面是我的Java代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MainConfig {
public static void main(String[] args) {
try{
dataSource();
System.out.println("conected");
}
catch(Exception ex){
ex.printStackTrace();
}
}
public static Connection dataSource() throws URISyntaxException, SQLException {
String ConnectionString ="jdbc:postgresql://l********n:cPd7VRjIhNVWOrZ4uWEeZWKYqV@ec2-184-73-251-115.compute-1.amazonaws.com:5432/dac36a93ohuvsd";
String username = "****";
String password = "***";
return DriverManager.getConnection(ConnectionString, username, password);
}
}
Run Code Online (Sandbox Code Playgroud)
我在控制台中遇到的错误是:
> org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:233)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:144)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:21)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:31)
at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:410)
at org.postgresql.Driver.connect(Driver.java:280)
at java.sql.DriverManager.getConnection(Unknown …
Run Code Online (Sandbox Code Playgroud) 你能解释一下为什么下面显示的方法是由Java编译和运行的
public static void testIf(int v){
if (v < 10)
if (v >20 )
System.out.println(" 20 IF");
else
System.out.println(" 20 ELSE");
else
System.out.println("10 Else");
}
Run Code Online (Sandbox Code Playgroud)
预先感谢您的帮助.
此致
java ×3
heroku ×1
if-statement ×1
postgresql ×1
regex ×1
string ×1
substitution ×1
substring ×1