I am using following code for SQLConnection in android:
public void queryResultSet(String CommandSQL) throws ClassNotFoundException, java.sql.SQLException
{
ResultSet rs;
Connection conn = null;
Toast msg1 = Toast.makeText(getBaseContext(),
"Name = " + CommandSQL, Toast.LENGTH_LONG);
msg1.show();
Class.forName("net.sourceforge.jtds.jdbc.Driver");
String username="14Graficali\\Administrator";
String ConnUrl="jdbc:jtds:sqlserver://14GRAFICALI\\MSSQLSERVER2008;DatabaseName=DVDKiosk;user=14Graficali\\Administrator;Instance=SQLExpress";
conn = DriverManager.getConnection(ConnUrl);
Statement st=conn.createStatement();
rs=st.executeQuery(CommandSQL);
while(rs.next())
{
Toast msg2 = Toast.makeText(getBaseContext(),
"Name = " + rs.getString("UserName"), Toast.LENGTH_LONG);
msg2.show();
}
}
I have included net.sourceforge.jtds.jdbc.Driver
as we can see below :
Stack Trace:
08-20 10:57:42.087: W/System.err(400): java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
08-20 10:57:42.087: W/System.err(400): at java.lang.Class.classForName(Native Method)
08-20 10:57:42.087: W/System.err(400): at java.lang.Class.forName(Class.java:234)
08-20 10:57:42.087: W/System.err(400): at java.lang.Class.forName(Class.java:181)
08-20 10:57:42.087: W/System.err(400): at com.example.registrationapp.Login.queryResultSet(Login.java:93)
08-20 10:57:42.087: W/System.err(400): at com.example.registrationapp.Login$1.onClick(Login.java:126)
08-20 10:57:42.087: W/System.err(400): at android.view.View.performClick(View.java:2485)
08-20 10:57:42.087: W/System.err(400): at android.view.View$PerformClick.run(View.java:9080)
08-20 10:57:42.087: W/System.err(400): at android.os.Handler.handleCallback(Handler.java:587)
08-20 10:57:42.087: W/System.err(400): at android.os.Handler.dispatchMessage(Handler.java:92)
08-20 10:57:42.098: W/System.err(400): at android.os.Looper.loop(Looper.java:123)
08-20 10:57:42.098: W/System.err(400): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-20 10:57:42.098: W/System.err(400): at java.lang.reflect.Method.invokeNative(Native Method)
08-20 10:57:42.098: W/System.err(400): at java.lang.reflect.Method.invoke(Method.java:507)
08-20 10:57:42.098: W/System.err(400): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-20 10:57:42.098: W/System.err(400): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-20 10:57:42.098: W/System.err(400): at dalvik.system.NativeStart.main(Native Method)
08-20 10:57:42.098: W/System.err(400): Caused by: java.lang.NoClassDefFoundError: net.sourceforge.jtds.jdbc.Driver
08-20 10:57:42.107: W/System.err(400): ... 16 more
08-20 10:57:42.107: W/System.err(400): Caused by: java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver in loader dalvik.system.PathClassLoader[/data/app/com.example.registrationapp-1.apk]
08-20 10:57:42.107: W/System.err(400): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-20 10:57:42.107: W/System.err(400): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-20 10:57:42.107: W/System.err(400): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
Please help me.