Home > database >  Android studio to connect to the database is normal, but the Connection. The createStatement () 
Android studio to connect to the database is normal, but the Connection. The createStatement () 

Time:10-30

The class DBUtil {
IP private static Connection getSQLConnection (String, String user, String PWD, String db)
{
The Connection con=null;
Try
{
Class.forname (".net. Sourceforge. JTDS. JDBC. The Driver ");
The d (" driver ", "getSQLConnection: success");
Con=DriverManager. GetConnection (" JDBC: JTDS: essentially://"+ IP +" : 1433/"+ db, the user, the PWD).
The d (" database connection ", "getSQLConnection: success");
} the catch (a ClassNotFoundException e)
{
e.printStackTrace();
} the catch (SQLException e)
{
e.printStackTrace();
}
Return con;
}

Public static String QuerySQL ()
{
The String result="";
Try
{

The Connection conn=getSQLConnection (" 192.168.0.102 ", "sa", "88888888", "parking");
The d (" parking ", "getSQLConnection: success");
String SQL="select the top 2 * from parking".
The Statement STMT=conn. CreateStatement ();//error code in the
The ResultSet rs=STMT. ExecuteQuery (SQL);
While (rs), next ())
{
String s1=rs. Get String (" Carid ");
String s2=rs. Get String (" Time ");
The result + + s2=s1 + "-" + "\ n";
System. The out. Println (s1 + "-" + s2);
}
rs.close();
STMT. Close ();
Conn. Close ();
} the catch (SQLException e)
{
e.printStackTrace();
Abnormal result +="!" + um participant etMessage ();
}
return result;
}

Public static void main (String [] args)
{
QuerySQL ();
}
}

CodePudding user response:

The ball ball bosses to give directions
  • Related