Name of the field in Java that takes out the form

Source: Internet
Author: User
Import java.sql.*;
Import java.util.ArrayList;
Import java.util.Hashtable;
Import java.util.List;
public class test{
public static void Main (string[] args) throws Exception {
Driven
String Driver = "Com.mysql.jdbc.Driver";
Database connection
String url = "Jdbc:mysql://localhost:3306/test";
User name
String user = "root";
Database Password
String Password = "admin";
Load Driver
Class.forName (driver);
Get links
Connection Connection = DriverManager
. getconnection (URL, user, password);
Create a query declaration
PreparedStatement PreparedStatement = Connection
. preparestatement ("SELECT * from dept");
Get results
ResultSet ResultSet = Preparedstatement.executequery ();
Get information for individual columns
ResultSetMetaData metaData = Resultset.getmetadata ();
A piece of data is saved in a Hashtable to store all Hashtable into the list
listwhile (Resultset.next ()) {
hashtable<string, object> row = new hashtable<string, object> ();
for (int i = 1; I <= metadata.getcolumncount (); i++) {
Print column names
System.out.println (Metadata.getcolumnname (i));
Row.put (Metadata.getcolumnname (i), resultset.getobject (i));
}
Rows.Add (row);
}
Resultset.close ();
Preparedstatement.close ();
Connection.close ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.