There are 15 code examples for java.sql.Connection.

The API names are highlighted below. You can use suckoo button to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.

Project Name: icTAKES Package: edu.mayo.bmi.dictionary.jdbc

Source Code: JdbcDictionaryImpl.java (Click to view .java file)

Method Code:
vote
like

private PreparedStatement initMetaDataPrepStmt(String text) throws SQLException {
  if (iv_mdPrepStmt == null) {
    StringBuffer sb=new StringBuffer();
    sb.append("SELECT ");
    Iterator metaFieldNameItr=getMetaFieldNames();
    while (metaFieldNameItr.hasNext()) {
      String mdFieldName=(String)metaFieldNameItr.next();
      sb.append(mdFieldName);
      sb.append(',');
    }
    sb.deleteCharAt(sb.length() - 1);
    sb.append(" FROM ");
    sb.append(iv_tableName);
    sb.append(" WHERE ");
    sb.append(iv_lookupFieldName);
    sb.append(" = ?");
    iv_mdPrepStmt=iv_dbConn.prepareStatement(sb.toString());
  }
  iv_mdPrepStmt.clearParameters();
  iv_mdPrepStmt.setString(1,text);
  return iv_mdPrepStmt;
}
 

Project Name: icTAKES Package: edu.mayo.bmi.uima.core.cr

Source Code: JdbcCollectionReader.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Slice up the query SQL and rebuild a SQL statement that gets a row count;
 * @param querySql
 * @return
 */
private int getRowCount(Connection conn,String querySql) throws SQLException {
  StringBuffer sb=new StringBuffer();
  sb.append("SELECT COUNT(*) ");
  int idx=querySql.indexOf("FROM");
  sb.append(querySql.subSequence(idx,querySql.length()));
  PreparedStatement cntStmt=conn.prepareStatement(sb.toString());
  if (usePrepStmtVals) {
    int totalCnt=0;
    for (int i=0; i < prepStmtValArr.length; i++) {
      List valList=prepStmtValArr[i];
      setPrepStmtValues(cntStmt,valList);
      ResultSet rs=cntStmt.executeQuery();
      rs.next();
      totalCnt+=rs.getInt(1);
    }
    return totalCnt;
  }
 else {
    ResultSet rs=cntStmt.executeQuery();
    rs.next();
    return rs.getInt(1);
  }
}
 

Project Name: icTAKES Package: edu.mayo.bmi.uima.core.resource

Source Code: JdbcConnectionResourceImpl.java (Click to view .java file)

Method Code:
vote
like

public Connection getConnection(){
  return iv_conn;
}
 

Project Name: icTAKES Package: edu.mayo.bmi.uima.lookup.ae

Source Code: UmlsToSnomedDbConsumerImpl.java (Click to view .java file)

Method Code:
vote
like

public UmlsToSnomedDbConsumerImpl(UimaContext aCtx,Properties properties) throws Exception {
  super(aCtx,properties);
  String resrcName=props.getProperty(DB_CONN_RESRC_KEY_PRP_KEY);
  JdbcConnectionResource resrc=(JdbcConnectionResource)aCtx.getResourceObject(resrcName);
  String prepStmtSql=props.getProperty(MAP_PREP_STMT_PRP_KEY);
  Connection conn=resrc.getConnection();
  mapPrepStmt=conn.prepareStatement(prepStmtSql);
}
 

Project Name: jFreeChart Package: org.jfree.data.jdbc

Source Code: JDBCXYDataset.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Close the database connection
 */
public void close(){
  try {
    this.connection.close();
  }
 catch (  Exception e) {
    System.err.println("JdbcXYDataset: swallowing exception.");
  }
}
 

Project Name: jFreeChart Package: org.jfree.data.jdbc

Source Code: JDBCPieDataset.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Close the database connection
 */
public void close(){
  try {
    this.connection.close();
  }
 catch (  Exception e) {
    System.err.println("JdbcXYDataset: swallowing exception.");
  }
}
 

Project Name: jbidwatcher Package: com.jbidwatcher.util.db

Source Code: Database.java (Click to view .java file)

Method Code:
vote
like

public Connection getConnection(){
  return mConn;
}
 

Project Name: openhotelsystem Package: it.hotel.model.abstrakt.manager

Source Code: AbstractDAO.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Chiude in modo controllato una connessione, 
 * senza rilanciare eccezioni. Da usare nel finally di gestione di
 * una eccezione.
 * @param conn La connessione al db; può esser null
 */
protected void closeConnection(Connection conn){
  try {
    if (conn != null)     conn.close();
  }
 catch (  Throwable t) {
    SystemUtils.logThrowable(t,this,"closeDaoStatement","Error in closing statement");
  }
}
 

Project Name: openhotelsystem Package: it.hotel.model.permission.manager

Source Code: PermissionDAO.java (Click to view .java file)

Method Code:
vote
like

public void deletePermission(String permissionName){
  Connection conn=null;
  PreparedStatement stat=null;
  try {
    conn=this.getConnection();
    conn.setAutoCommit(false);
    stat=conn.prepareStatement(DELETE_PERMISSION);
    stat.setString(1,permissionName);
    stat.executeUpdate();
    conn.commit();
  }
 catch (  Throwable t) {
    this.executeRollback(conn);
    processDaoException(t,"Errore in cancellazione permesso","deletePermission");
  }
 finally {
    closeDaoResources(null,stat,conn);
  }
}
 

Project Name: openhotelsystem Package: it.hotel.model.role.manager

Source Code: RoleDAO.java (Click to view .java file)

Method Code:
vote
like

public int getRoleUses(Role role){
  Connection conn=null;
  int num=0;
  PreparedStatement stat=null;
  ResultSet res=null;
  try {
    conn=this.getConnection();
    stat=conn.prepareStatement(NUMBER_OF_USER_WITH_ROLE);
    stat.setString(1,role.getName());
    res=stat.executeQuery();
    res.next();
    num=res.getInt(1);
  }
 catch (  Throwable t) {
    processDaoException(t,"Errore in estrazione numero utenti con ruolo","getNumberOfUserWithRole");
  }
 finally {
    closeDaoResources(res,stat,conn);
  }
  return num;
}
 

Project Name: openhotelsystem Package: it.hotel.model.user.manager

Source Code: UserDAO.java (Click to view .java file)

Method Code:
vote
like

/** 
 * @throws
	 * @
 * param rolename, the role of which we want to have user names.
 * @return a list of strings that contains userNames of 
 * the users with the specified role roleName. 
 */
public List<String> loadUserNamesWithRole(String rolename){
  List<String> userNames=new ArrayList<String>();
  PreparedStatement stat=null;
  ResultSet res=null;
  Connection conn=null;
  try {
    conn=this.getConnection();
    stat=conn.prepareStatement(SELECT_USERS_WITH_ROLE);
    stat.setString(1,rolename);
    res=stat.executeQuery();
    while (res.next()) {
      String userName=res.getString(1);
      userNames.add(userName);
    }
  }
 catch (  Throwable t) {
    processDaoException(t,"Error in accessing list of users with role","loadUsersWithRole");
  }
 finally {
    closeDaoResources(res,stat,conn);
  }
  return userNames;
}
 

Project Name: tudu Package: java.tudu.web.servlet

Source Code: DumpDatabaseServlet.java (Click to view .java file)

Method Code:
vote
like

protected final void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
  Writer writer=response.getWriter();
  try {
    Context ctx=new InitialContext();
    DataSource dataSource=(DataSource)ctx.lookup("java:comp/env/jdbc/tudu");
    Connection jdbcConnection=dataSource.getConnection();
    IDatabaseConnection connection=new DatabaseConnection(jdbcConnection);
    IDataSet fullDataSet=connection.createDataSet();
    response.setContentType("Content-Type: application/force-download");
    FlatXmlDataSet.write(fullDataSet,writer);
  }
 catch (  Exception e) {
    writer.write("An error has occured : " + e.getMessage());
    e.printStackTrace();
  }
 finally {
    writer.close();
  }
}
 

Project Name: weka Package: weka.core.converters

Source Code: DatabaseConnection.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Gets meta data for the database connection object.
 * @return the meta data.
 * @throws Exception if an error occurs
 */
public DatabaseMetaData getMetaData() throws Exception {
  if (!isConnected())   throw new IllegalStateException("Not connected, please connect first!");
  return m_Connection.getMetaData();
}
 

Project Name: weka Package: weka.experiment

Source Code: DatabaseResultListener.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Determines if there are any constraints (imposed by the
 * destination) on any additional measures produced by
 * resultProducers. Null should be returned if there are NO
 * constraints, otherwise a list of column names should be
 * returned as an array of Strings. In the case of
 * DatabaseResultListener, the structure of an existing database
 * will impose constraints.
 * @param rp the ResultProducer to which the constraints will apply
 * @return an array of column names to which resutltProducer's
 * results will be restricted.
 * @throws Exception if an error occurs.
 */
public String[] determineColumnConstraints(ResultProducer rp) throws Exception {
  FastVector cNames=new FastVector();
  updateResultsTableName(rp);
  DatabaseMetaData dbmd=m_Connection.getMetaData();
  ResultSet rs;
  if (m_checkForUpperCaseNames) {
    rs=dbmd.getColumns(null,null,m_ResultsTableName.toUpperCase(),null);
  }
 else {
    rs=dbmd.getColumns(null,null,m_ResultsTableName,null);
  }
  boolean tableExists=false;
  int numColumns=0;
  while (rs.next()) {
    tableExists=true;
    String name=rs.getString(4);
    if (name.toLowerCase().startsWith("measure")) {
      numColumns++;
      cNames.addElement(name);
    }
  }
  if (!tableExists) {
    return null;
  }
  String[] columnNames=new String[numColumns];
  for (int i=0; i < numColumns; i++) {
    columnNames[i]=(String)(cNames.elementAt(i));
  }
  return columnNames;
}
 

Project Name: weka Package: weka.gui.sql

Source Code: DbUtils.java (Click to view .java file)

Method Code:
vote
like

/** 
 * returns the current database connection.
 * @return        the current connection instance
 */
public Connection getConnection(){
  return m_Connection;
}