java手动连接JDBC
- 摘要:/***手动连接jdbc数据库连接*/packagecom.bjsxt.jbpm;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassJdbc{publicstaticvoidmain(String[]args){Stringurl="jdbc
- 标签:Java 连接
/**
* 手动连接jdbc数据库连接
*/
package com.bjsxt.jbpm;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Jdbc {
public static void main(String[] args) {
String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jdbc;User=sa;Password=sa";
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
Connection conn = (Connection) DriverManager.getConnection(url);
Statement st = (Statement) conn.createStatement();
String sql = "";
/*sql = "insert into userinfo (name,sex,phone) values( 'Tomqq','1','1234457') ";
st.executeUpdate(sql);*/
sql ="select name from userinfo where name = 'tomqq'";
ResultSet rs = st.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getString("name"));
}
st.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}// /:~