Although this may have been mentioned before here, It is worth mentioning again :
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
#AdditionalJar: jtds-1.3.1.jar
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
Dim MyJO As JavaObject = Me
Dim server As String ="//dbHost\sqlexpress";
Dim userid As String="sa"
Dim password As String="secret"
Dim sqlStr As String ="select * from users where id > 20"
Dim s As String = MyJO.RunMethod("DBConnect",Array(server,userid,password,sqlStr))
Log(s)
End Sub
#if Java
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
public static String DBConnect(String server, String userid, String password, String sqlStr) throws SQLException, ClassNotFoundException {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://"+ server, userid,password);
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sqlStr);
String result="";
while (rs.next()) {
result = result.concat(rs.getString("id") + ":" + rs.getString("usrname"));
}
return result;
}
#End If