How to Import Java.sql Record Counts
A Java.SQL connection is a session with your SQL database during which SQL statements are executed and returned based on your JavaScript commands. Applications based upon databases allow you to use Java programming to create your Web site. If you are looking for specific types of data or amounts of the data available within your SQL database, you can enter a record-count code into your HTML editor to access that information.
Instructions
-
-
1
Right-click the Java file from which you to wish to import the Java.SQL record counts and click "Open With." Click "Notepad" to launch the HTML editor.
-
2
Enter the following SQL files at the top of the Java file:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
Statement s = conn.createStatement();
ResultSet r = s.executeQuery("SELECT COUNT(*) AS rowcount FROM MyTable");
r.next();
int count = r.getInt("rowcount") ;
r.close() ;
System.out.println("MyTable has " + count + " row(s).");
Replace "MyTable" with the name of the table from which you wish to retrieve the record count.
-
-
3
Enter the following code to connect to the SQL database:
Connection connect;
connect = DriverManager.getConnection("sun.jdbc.odbc.JdbcOdbcDriver", "user", "pass");
Replace "user" and "pass" with your administrator's username and password.
-
4
Wait for the record counts to import. Type "con.close();" to close the connection to the server.
-
1