Hi
I'm trying to import the sql server jdbc driver into my project.
I right clicked my project and clicked import selected the sqljdbc4.jar file 
and imported it into the src directory.
My code is below but when it gets to Class.forName(driver).newInstance(); it 
gives an error 
java.lang.ClassNotFoundException: 
com.microsoft.sqlserver.jdbc.SQLServerDriver.class
What am i doing wrong? did I import it wrong?
if i type com.microsoft.sqlserver.jdbc.SQLServerDriver.class into the ide it 
doesnt complain so the file is there.
Any help would be great.
Thanks

package com.boozel.mobiletrend;

import java.sql.Connection;
import java.sql.DriverManager;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
//import com.microsoft.sqlserver.jdbc.*;

public class MobileTrendActivity extends Activity {
SharedPreferences sharedPreferences;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        sharedPreferences = getSharedPreferences("MobileTrend", 0);

    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.xml.mainmenu, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
        case R.id.settings:
        Intent myIntent = new Intent(MobileTrendActivity.this, 
Settings.class);
        MobileTrendActivity.this.startActivity(myIntent);
            return true;
        case R.id.connect:
        query();
        return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

 public void query()
 { 
 Log.i("MobileTrend","MySQL Connect Example.");
 Connection conn = null;
 String url = 
sharedPreferences.getString("url","jdbc:microsoft:sqlserver://localhost:1433");
 outputToConsole("Using URL: "+url);
 String dbName = sharedPreferences.getString("dbname","jdbctutorial");
 outputToConsole("Using DB Name: "+dbName);
 String driver = 
sharedPreferences.getString("driver","com.microsoft.sqlserver.jdbc.SQLServerDriver");
 outputToConsole("Using Driver: "+driver);
 String userName = sharedPreferences.getString("username","root");
 outputToConsole("Using UserName: "+userName);
 String password = sharedPreferences.getString("password","root");
 outputToConsole("Using Password: "+password);
 try {
 outputToConsole("Attempting to connect...");
 Class.forName(driver).newInstance();
 //test = com.microsoft.sqlserver.jdbc.SQLServerDriver.class;
 outputToConsole("Driver Instance Created");
 String connString = url +
   ";databaseName="+dbName+";user="+userName+";password="+password+";";
 outputToConsole("Connection String: "+connString);
 conn = DriverManager.getConnection(connString);
 //conn = DriverManager.getConnection(url+dbName,userName,password);
 outputToConsole("Connected to the database");
 conn.close();
 outputToConsole("Disconnected from database");
  } catch (Exception e) 
  { outputToConsole("ERROR: "+e);
  e.printStackTrace();
  }
 }

 public void outputToConsole(String message)
 {
 TextView tv = (TextView)findViewById(R.id.output);
 tv.append(message+"\n");
 Log.i("MobileTrend",message);
 }
 
 
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to