You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jh...@apache.org on 2022/04/13 16:19:29 UTC

[netbeans] branch master updated: Jdbc url templates in the Add DB Connection command (#3970)

This is an automated email from the ASF dual-hosted git repository.

jhorvath pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 422dd06629 Jdbc url templates in the Add DB Connection command (#3970)
422dd06629 is described below

commit 422dd06629726bd5c2c2f38781bbb40078ae6cad
Author: jhorvath <ja...@horvath.cz>
AuthorDate: Wed Apr 13 18:19:24 2022 +0200

    Jdbc url templates in the Add DB Connection command (#3970)
    
    Jdbc url templates in the Add DB Connection command
---
 .../modules/java/lsp/server/db/DBAddConnection.java    | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBAddConnection.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBAddConnection.java
index 2412d0bd08..414e78ce6b 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBAddConnection.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/db/DBAddConnection.java
@@ -26,6 +26,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -75,7 +76,16 @@ public class DBAddConnection extends CodeActionsProvider {
     public static final String DB_URL =  "url"; // NOI18N
     public static final String SCHEMA =  "schema"; // NOI18N
     public static final String DISPLAY_NAME =  "displayName"; // NOI18N
-    
+
+    private static final Map<String, String> urlTemplates = new HashMap<> ();
+    static {
+        urlTemplates.put("org.postgresql.Driver", "jdbc:postgresql://<HOST>:5432/<DB>");
+        urlTemplates.put("org.gjt.mm.mysql.Driver", "jdbc:mysql://<HOST>:3306/<DB>");
+        urlTemplates.put("com.mysql.cj.jdbc.Driver", "jdbc:mysql://<HOST>:3306/<DB>");
+        urlTemplates.put("org.mariadb.jdbc.Driver", "jdbc:mariadb://<HOST>:3306/<DB>");
+        urlTemplates.put("oracle.jdbc.OracleDriver", "jdbc:oracle:thin:@//<HOST>[:<PORT>][/<SERVICE>]");
+        urlTemplates.put("com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver://<HOST>\\<DB>[:<PORT>]");
+    }
     private final Gson gson = new Gson();
 
     @Override
@@ -148,8 +158,12 @@ public class DBAddConnection extends CodeActionsProvider {
                     if (!selectedItems.isEmpty()) {
                         int i = ((Double) selectedItems.get(0).getUserData()).intValue();
                         JDBCDriver driver = drivers[i];
+                        String urlTemplate = driver.getClassName() != null ? urlTemplates.get(driver.getClassName()) : "";
+                        if (urlTemplate == null) {
+                            urlTemplate = "";
+                        }
                         client.showInputBox(new ShowInputBoxParams(
-                                Bundle.MSG_EnterDbUrl(), "")).thenAccept((u) -> {
+                                Bundle.MSG_EnterDbUrl(), urlTemplate)).thenAccept((u) -> {
                             if (u == null) {
                                 return;
                             }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists