Difference between revisions of "Sql java file"

From MyWiki
Jump to: navigation, search
(Created page with "<source lang="java"? import java.sql.*; class Sql{ Connection conn = null; Statement stmt = null; ResultSet rs = null; void runIt() { try {...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<source lang="java"?
+
<source lang="java">
 
import java.sql.*;
 
import java.sql.*;
 
class Sql{
 
class Sql{
Line 8: Line 8:
 
{
 
{
 
   try {
 
   try {
               String userName = "solar";
+
               String userName = "xxxxx";
               String passWord = "solar";
+
               String passWord = "xxxxx";
               String url = "jdbc:mysql://localhost/solar";
+
               String url = "jdbc:mysql://localhost/xxxxx";
 
               //Class.forName ("com.mysql.jdbc.Driver").newInstance ();
 
               //Class.forName ("com.mysql.jdbc.Driver").newInstance ();
 
               conn = DriverManager.getConnection (url, userName, passWord);
 
               conn = DriverManager.getConnection (url, userName, passWord);
Line 25: Line 25:
 
System.out.println("The voltge in the Sql class is "+ voltage);
 
System.out.println("The voltge in the Sql class is "+ voltage);
 
   try {
 
   try {
               String userName = "solar";
+
               String userName = "xxxxx";
               String passWord = "solar";
+
               String passWord = "xxxxx";
               String url = "jdbc:mysql://localhost/solar";
+
               String url = "jdbc:mysql://localhost/xxxxx";
 
               //Class.forName ("com.mysql.jdbc.Driver").newInstance ();
 
               //Class.forName ("com.mysql.jdbc.Driver").newInstance ();
 
               conn = DriverManager.getConnection (url, userName, passWord);
 
               conn = DriverManager.getConnection (url, userName, passWord);

Latest revision as of 17:14, 25 April 2025

import java.sql.*;
class Sql{
      Connection conn = null;
      Statement stmt  = null;
      ResultSet rs    = null;
void runIt()
{
   try {
               String userName = "xxxxx";
               String passWord = "xxxxx";
               String url = "jdbc:mysql://localhost/xxxxx";
               //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 = "xxxxx";
               String passWord = "xxxxx";
               String url = "jdbc:mysql://localhost/xxxxx";
               //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);
                                }
}
         }