import java.sql.*
/*
* MYSQL的桥连接与直连接
*/
public class test {
public static void main(String[] args) {
try {
//MYSQL直连字符串
String driver = "org.gjt.mm.mysql.Driver"
String url = "jdbc:mysql://localhost/mysql?useUnicode=true&characterEncoding=gb2312"
//MYSQL桥连字符串
// String driver = "sun.jdbc.odbc.JdbcOdbcDriver"
// String url = "jdbc:odbc:test"
String user = "root"
String pwd = "msconfig"
Class.forName(driver)
Connection con = DriverManager.getConnection(url,user,pwd)
PreparedStatement pstmt = con.prepareStatement("select * from user")
ResultSet rs = pstmt.executeQuery()
while(rs.next()){
for (int i = 1i <= rs.getMetaData().getColumnCount()i++){
System.out.print(rs.getString(i) + "\t")
}
System.out.println()
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace()
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)