Sql java file

From MyWiki
Revision as of 17:12, 25 April 2025 by George2 (Talk | contribs)

Jump to: navigation, search
import java.sql.*;
class Sql{
      Connection conn = null;
      Statement stmt  = null;
      ResultSet rs    = null;
void runIt()
{
   try {
               String userName = "solar";
               String passWord = "solar";
               String url = "jdbc:mysql://localhost/solar";
               //Class.forName ("com.mysql.jdbc.Driver").newInstance ();
               conn = DriverManager.getConnection (url, userName, passWord);
               System.out.println("connection esstablsihed in Sql");
               conn.close();
       }
          catch (SQLException e){ 
                                 String errorCode = e.toString();
                                 System.out.println(errorCode);
                                }
}
void runIt(String voltage)
{
System.out.println("The voltge in the Sql class is "+ voltage);
   try {
               String userName = "solar";
               String passWord = "solar";
               String url = "jdbc:mysql://localhost/solar";
               //Class.forName ("com.mysql.jdbc.Driver").newInstance ();
               conn = DriverManager.getConnection (url, userName, passWord);
               System.out.println("connection esstablsihed in Sql");
	       Float the_volt = Float.parseFloat(voltage);
	       String SQL="insert into solar VALUES("+the_volt+", now())";
	       Statement statement = conn.createStatement();
	       statement.executeUpdate(SQL);
 
               conn.close();
       }
          catch (SQLException e){ 
                                 String errorCode = e.toString();
                                 System.out.println(errorCode);
                                }
}
         }