PowerBuilder Connect SQLServer Using JDBC
Step 1: Get driver JDBC SQLServer mssql-jdbc-x.x.x.jar from page : https://docs.microsoft.com/en-us/sql/connect/jdbc/microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15
Step 2: Set Class Path driver to environment variables or set class path to runtime of java
Step 3: Test Connect
Step 4: Copy jre current version of java to your pbapp runtime
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
String ls_path, ls_classpath Boolean lb_jvm_started, lb_debug javavm ljvm ls_path = GetCurrentDirectory ( ) // set classpath or you can environment variables of window ls_classpath = ls_path + "\sqljdbc_8.4\enu\mssql-jdbc-8.4.1.jre8.jar" If Not FileExists(ls_classpath) Then MessageBox('Warning',"driver class file not exists") Return End If If Not lb_jvm_started Then ljvm = Create javavm //using pbejbclientXXX.pbd Choose Case ljvm.createJavaVM(ls_classpath, lb_debug) Case 0 lb_jvm_started = True Case -1 MessageBox('Warning',"Failed to load JavaVM") Return Case -2 MessageBox('Warning',"Failed to load EJBLocator") Return End Choose End If // get infor String ls_url, ls_database, ls_servername, ls_port, ls_user, ls_pass ls_user = "user" ls_pass = "password" ls_database = "database" ls_servername = "servername.com" ls_port = "port" ls_url = "jdbc:sqlserver://"+ls_servername+":"+ls_port+";databaseName=" + ls_database //connect Transaction ltran_conn ltran_conn = Create Transaction ltran_conn.DBMS = "JDBC" ltran_conn.LogPass = ls_pass ltran_conn.LogID = ls_user ltran_conn.AutoCommit = False ltran_conn.DBParm = "Driver='com.microsoft.sqlserver.jdbc.SQLServerDriver',URL='" + ls_url + "'" Connect Using ltran_conn ; If ltran_conn.SQLCode = -1 Then MessageBox('Warning','Connect Database Error' + ltran_conn.SQLErrText) Else MessageBox('Warning',"Connect Success!") End If Disconnect Using ltran_conn ; |
Find Projects On Github click here
Good Luck!
Subscribe
Login
0 Comments