代码:
package 数据库连接;
import java.sql.*;
public class DongTai {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/lg", //数据库连接已成功
"root","zxx15935930051gl");
String sql = "select *from zxx where name=? or gender=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setObject(1,"%");
ps.setObject(2,"男");
ResultSet res = ps.executeQuery();
System.out.println("name\tage\tgender\tjobtime");
while(res.next()) {
System.out.println(res.getObject(1)+"\t"+res.getObject(2)+"\t"+res.getObject(3)+"\t"+res.getObject(4));
}
}catch (Exception e) {
e.printStackTrace();
}finally {
if(con!=null) {
try {
con.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
}
}
控制台:<ConnectionProperties>
<PropertyCategory name="Connection/Authentication">
<Property name="user" required="No" default="" sortOrder="-2147483647" since="all versions">
The user to connect as
</Property>
<Property name="password" required="No" default="" sortOrder="-2147483646" since="all versions">
The password to use when connecting
</Property>
<Property name="socketFactory" required="No" default="com.mysql.jdbc.StandardSocketFactory" sortOrder="4" since="3.0.3">
The name of the class that the driver should use for creating socket connections to the server. This class must implement the interface 'com.mysql.jdbc.SocketFactory' and have public no-args constructor.
</Property>
<Property name="connectTimeout" required="No" default="0" sortOrder="9" since="3.0.1">
Timeout for socket connect (in milliseconds), with 0 being no timeout. Only works on JDK-1.4 or newer. Defaults to '0'.
</Property>
<Property name="socketTimeout" required="No" default="0" sortOrder="10" since="3.0.1">
Timeout on network socket operations (0, the default means no timeout).
</Property>
<Property name="connectionLifecycleInterceptors" required="No" default="" sortOrder="2147483647" since="5.1.4">
A comma-delimited list of classes that implement "com.mysql.jdbc.ConnectionLifecycleInterceptor" that should notified of connection lifecycle events (creation, destruction, commit, rollback, setCatalog and setAutoCommit) and potentially alter the execution of these commands. ConnectionLifecycleInterceptors are "stackable", more than one interceptor may be specified via the configuration property as a comma-delimited list, with the interceptors executed in order from left to right.
</Property>
<Property name="useConfigs" required="No" default="" sortOrder="2147483647" since="3.1.5">
Load the comma-delimited list of configuration properties before parsing the URL or applying user-specified properties. These configurations are explained in the 'Configurations' of the documentation.
</Property>
<Property name="authenticationPlugins" required="No" default="" sortOrder="alpha" since="5.1.19">
Comma-delimited list of classes that implement com.mysql.jdbc.AuthenticationPlugin and which will be used for authentication unless disabled by "disabledAuthenticationPlugins" property.
</Property>
<Property name="defaultAuthenticationPlugin" required="No" default="com.mysql.jdbc.authentication.MysqlNativePasswordPlugin" sortOrder="alpha" since="5.1.19">
Name of a class implementing com.mysql.jdbc.AuthenticationPlugin which will be used as the default authentication plugin (see below). It is an error to use a class which is not listed in "authenticationPlugins" nor it is one of the built-in plugins. It is an error to set as default a plugin which was disabled with "disabledAuthenticationPlugins" property. It is an error to set this value to null or the empty string (i.e. there must be at least a valid default authentication plugin specified for the connection, meeting all constraints listed above).
</Property>
<Property name="disabledAuthenticationPlugins" required="No" default="" sortOrder="alpha" since="5.1.19">
Comma-delimited list of classes implementing com.mysql.jdbc.AuthenticationPlugin or mechanisms, i.e. "mysql_native_password". The authentication plugins or mechanisms listed will not be used for authentication which will fail if it requires one of them. It is an error to disable the default authentication plugin (either the one named by "defaultAuthenticationPlugin" property or the hard-coded one if "defaultAuthenticationPlugin" property is not set).
</Property>
<Property name="disconnectOnExpiredPasswords" required="No" default="true" sortOrder="alpha" since="5.1.23">
If "disconnectOnExpiredPasswords" is set to "false" and password is expired then server enters "sandbox" mode and sends ERR(08001, ER_MUST_CHANGE_PASSWORD) for all commands that are not needed to set a new password until a new password is set.
</Property>
<Property name="interactiveClient" required="No" default="false" sortOrder="alpha" since="3.1.0">
Set the CLIENT_INTERACTIVE flag, which tells MySQL to timeout connections based on INTERACTIVE_TIMEOUT instead of WAIT_TIMEOUT
</Property>
<Property name="localSocketAddress" required="No" default="" sortOrder="alpha" since="5.0.5">
Hostname or IP address given to explicitly configure the interface that the driver will bind the client side of the TCP/IP connection to when connecting.
</Property>
<Property name="propertiesTransform" required="No" default="" sortOrder="alpha" since="3.1.4">
An implementation of com.mysql.jdbc.ConnectionPropertiesTransform that the driver will use to modify URL properties passed to the driver before attempting a connection
</Property>
<Property name="useCompression" required="No" default="false" sortOrder="alpha" since="3.0.17">
.................................................................后面还有一堆