Results 1 to 3 of 3
Thread: problem with sql connection
- 11-01-2011, 04:42 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 1
- Rep Power
- 0
problem with sql connection
dear friend. i got problem to connect java apps with sql database. this implementation made by using dk1.6,mysql xamp,jdbc.
when run it,the error with message "not suitable driver found for jdbc. already tried to install the jdbc driver n set classpath, but not succeeded.im begging for help here . before that,thankyou and forgive my english
this link,show my output : imgPlace.com - Image Hosting - Free Image Hosting - Free Image Uploading - image 6026
here my code:
import java.util.*;
import java.io.*;
import java.sql.*;
import java.lang.*;
public class function{
public static String filename;
public static Scanner input;
public static String[] data;
public void uploadSQL() {
System.out.println("============================== =========");
System.out.println("\tUpload to SQL :"+filename);
System.out.println("============================== =========");
try{
//Connection conn = null;
Statement stmt = null;
//prepareStatement = null;
ResultSet rs = null;
//load JDBC Driver
/* try{
Class.forName("com.mysql.jdbc.Driver").newInstance ();
System.out.println("Driver loaded");
}
catch (Exception ex) {
}*/
//Establish a connection
String url = "jdbc:mysql://localhost/company?user=root&password=tiger";
Connection conn = DriverManager.getConnection(url,"root","tiger");
//conn =DriverManager.getConnection("jdbc:mysql://localhost/mydatabase?"+"userName=root&password=tiger");
System.out.println("Database connected");
//Create statement
stmt = conn.createStatement();
rs = stmt.executeQuery("INSERT INTO student(name,matric,gender,state,faculty)"+ "values(?,?,?,?,?)");
try{
FileReader fr = new FileReader(new File(filename));
BufferedReader br = new BufferedReader(fr);
String value;
while((value = br.readLine()) != null){
String[] column = value.split(",");
for(int i = 0; i<column.length; i++){
if(!column[i].trim().equals("")) {
rs = stmt.executeQuery(column[i]);
//System.out.println(">>"+column[i]);
}
}
}
br.close();
}
catch(IOException e){
e.printStackTrace();
System.out.println("File not found!");
}
System.out.println("successful insert data");
System.out.println("All data are inserted in the database table");
//Close the connection
conn.close();
}
catch(SQLException ex){
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
//System.out.println("Not found");
}
}
public void readFromFile(){
try{
System.out.println();
System.out.println("============================== =======================");
System.out.println("\tWELCOME TO JAVA APPLICATION");
System.out.println("============================== =======================");
System.out.println();
System.out.print("Enter CSV file name:\t");
//System.out.println();
Scanner readkey = new Scanner(System.in);
filename = readkey.next();
//use buffering
FileInputStream file = new FileInputStream(filename);
DataInputStream data = new DataInputStream(file);
BufferedReader input = new BufferedReader(new InputStreamReader(data));
System.out.println("File Found!");
data.close();
file.close();
input.close();
}
catch(IOException e){
e.printStackTrace();
System.out.println("File not found!");
}
}
}
- 01-06-2012, 08:19 AM #2
Member
- Join Date
- Feb 2010
- Posts
- 80
- Rep Power
- 0
Re: problem with sql connection
the code is really painful for the eyes. try formatting it.
[why are you annoyed with my sig?]
- 01-06-2012, 08:27 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: problem with sql connection
If you don't know how to format please have a look at my forum signature (or forum FAQ). I have added a link to that page there.
Similar Threads
-
Connection problem
By Levian in forum JDBCReplies: 4Last Post: 09-13-2011, 02:23 AM -
URL connection problem
By rajeshgubba in forum New To JavaReplies: 8Last Post: 04-23-2009, 06:22 PM -
Too many Connection Problem Plz Help
By shuvra_pan in forum Advanced JavaReplies: 3Last Post: 03-17-2009, 01:42 PM -
connection problem
By subash in forum JDBCReplies: 5Last Post: 04-22-2008, 09:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks