Hello,
i'm working on netbeans and want to access my database using this code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class connect {
/**
* @param args
*/
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch (Exception ex) {
System.out.println("error \n");
}
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/university", "root", "");
// Do something with the Connection
Statement stmt = null;
ResultSet rs = null;
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM student");
int numCols = rs.getMetaData().getColumnCount ();
while ( rs.next() ) {
for (int i=1; i<=numCols; i++) {
System.out.print("<td>" + rs.getString(i) + "</td>" );
} // end for
System.out.println("\n");
} // end while
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
}
everytime i run the program i get this message:
error
SQLException: No suitable driver found for jdbc:mysql://localhost:3306/university
SQLState: 08001
VendorError: 0
The code is working very well on Eclipse ... but i cant get it running on netbeas even though i added the needed driver for it to run and it says that its already connect.