Skip to main content

NetBeans is underlining words/lines in grey

2 replies [Last post]
rpjd
Offline
Joined: 2008-01-02
Points: 0

I am creating a program to query a MySQL database. for some reason I don't understand, NB is underlining certain words/lines in grey. If someone can explain why, I would be grateful. This my code so far.

package Statistics;
import java.sql.*;
import java.util.*;
import javax.swing.table.*;
import java.lang.*;

/**
*
* @author RichardDunne
*/
public class stats {
private String Connector = "com.mysql.jdbc.Driver";
private String DATABASE_URL = "jdbc:mysql://localhost:3306/Questions";
private String Username="user";
private String Password="password";

private Connection connection;
private Statement stmt;
private boolean connected = false;

public void Connect(String Connector, String DATABASE_URL, String Query) throws SQLException, ClassNotFoundException
{
Class.forName(Connector);
connection = DriverManager.getConnection(DATABASE_URL,Username,Password);
stmt = connection.createStatement();
if(!connected) throw new IllegalStateException("Connection failed");
}

public void countRows()
{
try{
ResultSet countRows = stmt.executeQuery("select count(*) as countRows from answers;");
}
catch(SQLException sqlException)
{
System.out.println("query failed");
}
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rpjd
Offline
Joined: 2008-01-02
Points: 0

wrongly placed return statement

rpjd
Offline
Joined: 2008-01-02
Points: 0

I am getting this error : expected '(' at
private static void Connection getMyqlConnection() throws Exception{
in my code below but I can't see the error myself, possibly not obvious to a Java/NB novice! If anyone can point out whats wring, I would be grateful. Previous subject Q can be ignored.

package Statistics;
import java.sql.*;
import java.util.*;
import javax.swing.table.*;
import java.lang.*;

/**
*
* @author RichardDunne
*/

public class stats {
private static void Connection getMyqlConnection() throws Exception{
String Connector = "com.mysql.jdbc.Driver";
String DATABASE_URL = "jdbc:mysql://localhost:3306/Questions";
String Username="root";
String Password="highbury";

Class.forName(Connector);
Connection conn = DriverManager.getConnection(DATABASE_URL,Username,Password);
try{
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select count(*) as countRows from answers");
int rowCount = rs.getInt("countRows");
}

catch(SQLException sqlException)
{
System.out.println("query failed");
}
}
}