package zixue.jdbc;import java.sql.Connection;import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;public class Base {
static void test() throws SQLException,ClassNotFoundException{
//注册驱动
Class.forName("com.mysql.jdbc.Driver");
//DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//建立连接
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/jdbc","root","woaiyan");
//创建语句
Statement st = conn.createStatement();
//执行语句
ResultSet rs = st.executeQuery("select * from user");
//处理结果
while(rs.next()){
System.out.print(rs.getObject(1)+"\t"+rs.getObject(2)+
"\t"+rs.getObject(3)+"\t");
}
//释放资源
rs.close();
st.close();
conn.close();
}
}
这是我的代码
驱动也有加进去
但是每次运行都显示不出查询的结果
控制台的信息是:
<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>
。(还有很多)
我研究了半天了 换过SQL 换过驱动 也是一样的~
还有 我用MySQL的dos界面中查询可以查出我得 JDBC数据库中得JDBC表
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;public class Base {
static void test() throws SQLException,ClassNotFoundException{
//注册驱动
Class.forName("com.mysql.jdbc.Driver");
//DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//建立连接
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/jdbc","root","woaiyan");
//创建语句
Statement st = conn.createStatement();
//执行语句
ResultSet rs = st.executeQuery("select * from user");
//处理结果
while(rs.next()){
System.out.print(rs.getObject(1)+"\t"+rs.getObject(2)+
"\t"+rs.getObject(3)+"\t");
}
//释放资源
rs.close();
st.close();
conn.close();
}
}
这是我的代码
驱动也有加进去
但是每次运行都显示不出查询的结果
控制台的信息是:
<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>
。(还有很多)
我研究了半天了 换过SQL 换过驱动 也是一样的~
还有 我用MySQL的dos界面中查询可以查出我得 JDBC数据库中得JDBC表
解决方案 »
- java新手,主类的关系?提示总是“找不到主类”
- spring +dwr 报错 求大家解决 感谢
- Eclipse调试
- 急急急...............myeclipse部署weblogic9.2问题
- apache屏蔽路径后为什么不能用迅雷下载
- jsp里面table有行数据怎么上传给action 求高手指点!!!
- 查询变慢,如何优化
- 提问:Struts
- 各位前辈,救救我吧!我的SQL SERVER数据库中有时间字段create_date(数值为2003-3-4这种形式),在JSP中如何根据这个字段值筛选出某一周
- 初级问题
- 新手怎么学习J2EE
- 用JBulier布置好控件后为什么怎么也看不到?
System.out.prinln("ID"+rs.getInt(1)+"name"+rs.getString(2));
}
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;public class Base {
static void test() throws SQLException,ClassNotFoundException{
//注册驱动
Class.forName("com.mysql.jdbc.Driver");
//DriverManager.registerDriver(new com.mysql.jdbc.Driver());//建立连接
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/jdbc","root","woaiyan");//创建语句
Statement st = conn.createStatement();//执行语句
ResultSet rs = st.executeQuery("select * from user");//处理结果
if(rs==null){
System.out.println("查询结果为空");
}
while(rs.next()){
System.out.print(rs.getObject(1)+"\t"+rs.getObject(2)+
"\t"+rs.getObject(3)+"\t");
}
//释放资源
rs.close();
st.close();
conn.close();
} public static void main(String[] args){
try{
test();
}catch(Exception e){
e.printStackTrace();
}
}
}